zeroframework/Services/DeviceCenter/ZeroFramework.DeviceCenter.API/DependencyRegistrar.cs

30 lines
1.3 KiB
C#
Raw Permalink Normal View History

2023-12-05 09:22:48 +00:00
using Microsoft.AspNetCore.Authorization;
using ZeroFramework.DeviceCenter.API.Extensions.Authorization;
using ZeroFramework.DeviceCenter.API.Extensions.Hosting;
using ZeroFramework.DeviceCenter.Application.Services.Permissions;
namespace ZeroFramework.DeviceCenter.API
{
public static class DependencyRegistrar
{
public static IServiceCollection AddWebApiLayer(this IServiceCollection services)
{
var exportedTypes = System.Reflection.Assembly.GetExecutingAssembly().ExportedTypes;
var permissionDefinitionProviders = exportedTypes.Where(t => t.IsAssignableTo(typeof(IStartupFilter)));
permissionDefinitionProviders.ToList().ForEach(t => services.AddTransient(typeof(IStartupFilter), t));
services.AddLocalization(options => options.ResourcesPath = "Resources");
services.AddTransient<IPermissionChecker, PermissionChecker>();
services.AddSingleton<IAuthorizationPolicyProvider, CustomAuthorizationPolicyProvider>();
services.AddTransient<IAuthorizationHandler, PermissionRequirementHandler>();
services.AddTransient<IAuthorizationHandler, ResourcePermissionRequirementHandler>();
services.AddHttpContextAccessor();
services.AddHostedService<MockSampleWorker>();
return services;
}
}
}