Skip to content

Commit dfb27d8

Browse files
Auth handlers - any lifetime (dotnet#20309)
1 parent cc82002 commit dfb27d8

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

aspnetcore/security/authorization/dependencyinjection.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ uid: security/authorization/dependencyinjection
1111

1212
<a name="security-authorization-di"></a>
1313

14-
[Authorization handlers must be registered](xref:security/authorization/policies#handler-registration) in the service collection during configuration (using [dependency injection](xref:fundamentals/dependency-injection)).
14+
[Authorization handlers must be registered](xref:security/authorization/policies#handler-registration) in the service collection during configuration using [dependency injection](xref:fundamentals/dependency-injection).
1515

16-
Suppose you had a repository of rules you wanted to evaluate inside an authorization handler and that repository was registered in the service collection. Authorization will resolve and inject that into your constructor.
16+
Suppose you had a repository of rules you wanted to evaluate inside an authorization handler and that repository was registered in the service collection. Authorization resolves and injects that into the constructor.
1717

18-
For example, if you wanted to use ASP.NET's logging infrastructure you would want to inject `ILoggerFactory` into your handler. Such a handler might look like:
18+
For example, to use ASP.NET's logging infrastructure, inject `ILoggerFactory` into the handler. Such a handler might look like the following code:
1919

2020
```csharp
2121
public class LoggingAuthorizationHandler : AuthorizationHandler<MyRequirement>
@@ -36,13 +36,13 @@ public class LoggingAuthorizationHandler : AuthorizationHandler<MyRequirement>
3636
}
3737
```
3838

39-
You would register the handler with `services.AddSingleton()`:
39+
The preceding handler can be registered with any [service lifetime](/dotnet/core/extensions/dependency-injection#service-lifetimes). The following code uses `AddSingleton` to register the preceding handler:
4040

4141
```csharp
4242
services.AddSingleton<IAuthorizationHandler, LoggingAuthorizationHandler>();
4343
```
4444

45-
An instance of the handler will be created when your application starts, and DI will inject the registered `ILoggerFactory` into your constructor.
45+
An instance of the handler is created when the app starts, and DI injects the registered `ILoggerFactory` into the constructor.
4646

4747
> [!NOTE]
4848
> Handlers that use Entity Framework shouldn't be registered as singletons.

0 commit comments

Comments
 (0)