Skip to content

Commit

Permalink
fix: May not add CasbinAuthorizationHandler in some situations
Browse files Browse the repository at this point in the history
Signed-off-by: Sagilio <[email protected]>
  • Loading branch information
sagilio committed Mar 23, 2021
1 parent a06439c commit e5dc077
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Casbin.AspNetCore.Core/CoreServiceCollectionExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,13 @@ public static IServiceCollection AddCasbinAuthorizationCore(
services.TryAddSingleton<ICasbinAuthorizationContextFactory, DefaultCasbinAuthorizationContextFactory>();
services.TryAddScoped<IEnforceService, DefaultEnforcerService>();
services.TryAddSingleton<IRequestTransformersCache, RequestTransformersCache>();
services.TryAddScoped<IAuthorizationHandler, CasbinAuthorizationHandler>();
services.TryAddSingleton<IRequestTransformer, BasicRequestTransformer>();
services.TryAddSingleton<IRequestTransformer, RbacRequestTransformer>();
services.TryAddSingleton<IRequestTransformer, KeyMatchRequestTransformer>();

// Can not change to TryAdd, because there interface may need more than one implement.
services.AddScoped<IAuthorizationHandler, CasbinAuthorizationHandler>();
services.AddSingleton<IRequestTransformer, BasicRequestTransformer>();
services.AddSingleton<IRequestTransformer, RbacRequestTransformer>();
services.AddSingleton<IRequestTransformer, KeyMatchRequestTransformer>();

services.AddAuthorizationCore();
return services;
}
Expand Down

0 comments on commit e5dc077

Please sign in to comment.