private static void CheckOptions(CasbinAuthorizationCoreOptions options) { if (options.DefaultEnforcerFactory is null) { throw new ArgumentNullException(nameof(options.DefaultEnforcerFactory)); } }
public static IServiceCollection AddCasbinAuthorizationCore( this IServiceCollection services, Action <CasbinAuthorizationCoreOptions> configure, ServiceLifetime defaultModelProviderLifeTime = ServiceLifetime.Scoped, ServiceLifetime defaultEnforcerProviderLifeTime = ServiceLifetime.Scoped) { var options = new CasbinAuthorizationCoreOptions(); configure(options); CheckOptions(options); services.Configure(configure); services.TryAdd(ServiceDescriptor.Describe( typeof(ICasbinModelProvider), typeof(DefaultCasbinModelProvider), defaultModelProviderLifeTime)); services.TryAdd(ServiceDescriptor.Describe( typeof(IEnforcerProvider), typeof(DefaultEnforcerProvider), defaultEnforcerProviderLifeTime)); services.TryAddSingleton < ICasbinAuthorizationContextFactory, DefaultCasbinAuthorizationContextFactory>(); services.TryAddScoped <IAuthorizationHandler, CasbinAuthorizationHandler>(); services.TryAddScoped <IEnforceService, DefaultEnforcerService>(); services.AddSingleton <IRequestTransformer, BasicRequestTransformer>(); services.AddAuthorizationCore(); return(services); }