diff --git a/aspnetcore/fundamentals/configuration/options.md b/aspnetcore/fundamentals/configuration/options.md index dc136673a431..138c3699c3f5 100644 --- a/aspnetcore/fundamentals/configuration/options.md +++ b/aspnetcore/fundamentals/configuration/options.md @@ -462,20 +462,20 @@ For the preceding code, changes to the JSON configuration in the app settings fi * Does ***not*** support: * Reading of configuration data after the app has started. * [Named options](#specify-a-custom-key-name-for-a-configuration-property-using-configurationkeyname). -* Is registered as a [singleton service](/dotnet/core/extensions/dependency-injection#singleton) and can be injected into any [service lifetime](/dotnet/core/extensions/dependency-injection#service-lifetimes). +* Is registered as a [singleton service](/dotnet/core/extensions/dependency-injection/service-lifetimes#singleton) and can be injected into any [service lifetime](/dotnet/core/extensions/dependency-injection/service-lifetimes). : * Covered later in this article in the [Use `IOptionsSnapshot` to read updated data](#use-ioptionssnapshot-to-read-updated-data) section. * Is useful in scenarios where options should be recomputed on every request. -* Is registered as a [scoped service](/dotnet/core/extensions/dependency-injection#scoped), so it can't be injected into a singleton service. +* Is registered as a [scoped service](/dotnet/core/extensions/dependency-injection/service-lifetimes#scoped), so it can't be injected into a singleton service. * Supports [named options](#specify-a-custom-key-name-for-a-configuration-property-using-configurationkeyname). : * Covered later in this article in the [Use `IOptionsMonitor` to read updated data](#use-ioptionssnapshot-to-read-updated-data) section. * Is used to retrieve options and manage options notifications for `TOptions` instances. -* Is registered as a [singleton service](/dotnet/core/extensions/dependency-injection#singleton) and can be injected into any [service lifetime](/dotnet/core/extensions/dependency-injection#service-lifetimes). +* Is registered as a [singleton service](/dotnet/core/extensions/dependency-injection/service-lifetimes#singleton) and can be injected into any [service lifetime](/dotnet/core/extensions/dependency-injection/service-lifetimes). * Supports: * Change notifications. * [Named options](#specify-a-custom-key-name-for-a-configuration-property-using-configurationkeyname). @@ -491,13 +491,13 @@ For the preceding code, changes to the JSON configuration in the app settings fi Using : * Options are computed once per request when accessed and cached for the lifetime of the request. -* May incur a significant performance penalty because it's a [scoped service](/dotnet/core/extensions/dependency-injection#scoped) and is recomputed per request. For more information, see [`IOptionsSnapshot` is very slow (`dotnet/runtime` #53793)](https://github.com/dotnet/runtime/issues/53793) and [Improve the performance of configuration binding (`dotnet/runtime` #36130)](https://github.com/dotnet/runtime/issues/36130). +* May incur a significant performance penalty because it's a [scoped service](/dotnet/core/extensions/dependency-injection/service-lifetimes#scoped) and is recomputed per request. For more information, see [`IOptionsSnapshot` is very slow (`dotnet/runtime` #53793)](https://github.com/dotnet/runtime/issues/53793) and [Improve the performance of configuration binding (`dotnet/runtime` #36130)](https://github.com/dotnet/runtime/issues/36130). * Changes to the configuration are read after the app starts when using configuration providers that support reading updated configuration values. The difference between [`IOptionsMonitor`](#use-ioptionsmonitor-to-read-updated-data) and is that: -* is a [singleton service](/dotnet/core/extensions/dependency-injection#singleton) that retrieves current option values at any time, which is especially useful in singleton dependencies. -* is a [scoped service](/dotnet/core/extensions/dependency-injection#scoped) and provides a snapshot of the options at the time the `IOptionsSnapshot` object is constructed. Options snapshots are designed for use with transient and scoped dependencies. +* is a [singleton service](/dotnet/core/extensions/dependency-injection/service-lifetimes#singleton) that retrieves current option values at any time, which is especially useful in singleton dependencies. +* is a [scoped service](/dotnet/core/extensions/dependency-injection/service-lifetimes#scoped) and provides a snapshot of the options at the time the `IOptionsSnapshot` object is constructed. Options snapshots are designed for use with transient and scoped dependencies. The ASP.NET Core runtime uses to cache the options instance after it's created. @@ -620,8 +620,8 @@ After the app has started, changes to the JSON configuration in the app settings The difference between and [`IOptionsSnapshot`](#use-ioptionssnapshot-to-read-updated-data) is that: -* is a [singleton service](/dotnet/core/extensions/dependency-injection#singleton) that retrieves current option values at any time, which is especially useful in singleton dependencies. -* is a [scoped service](/dotnet/core/extensions/dependency-injection#scoped) and provides a snapshot of the options at the time the `IOptionsSnapshot` object is constructed. Options snapshots are designed for use with transient and scoped dependencies. +* is a [singleton service](/dotnet/core/extensions/dependency-injection/service-lifetimes#singleton) that retrieves current option values at any time, which is especially useful in singleton dependencies. +* is a [scoped service](/dotnet/core/extensions/dependency-injection/service-lifetimes#scoped) and provides a snapshot of the options at the time the `IOptionsSnapshot` object is constructed. Options snapshots are designed for use with transient and scoped dependencies. is used by to cache `TOptions` instances. invalidates options instances in the monitor so that the value is recomputed. Values can be manually introduced with . The method is used when all named instances should be recreated on demand. diff --git a/aspnetcore/fundamentals/dependency-injection.md b/aspnetcore/fundamentals/dependency-injection.md index 33afafeff4c2..e703f07fc8df 100644 --- a/aspnetcore/fundamentals/dependency-injection.md +++ b/aspnetcore/fundamentals/dependency-injection.md @@ -109,7 +109,7 @@ The following code is generated by the Razor Pages template using individual acc ## Service lifetimes -See [Service lifetimes](/dotnet/core/extensions/dependency-injection#service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Service lifetimes](/dotnet/core/extensions/dependency-injection/service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) To use scoped services in middleware, use one of the following approaches: @@ -120,7 +120,7 @@ For more information, see to obtain a service instance when you can use DI instead: @@ -349,11 +349,11 @@ The following table lists a small sample of these framework-registered services: * [NDC Conference Patterns for DI app development](https://www.youtube.com/watch?v=x-C-CNBVTaY) * * -* [Understand dependency injection basics in .NET](/dotnet/core/extensions/dependency-injection-basics) -* [Dependency injection guidelines](/dotnet/core/extensions/dependency-injection-guidelines) -* [Tutorial: Use dependency injection in .NET](/dotnet/core/extensions/dependency-injection-usage) +* [Understand dependency injection basics in .NET](/dotnet/core/extensions/dependency-injection/basics) +* [Dependency injection guidelines](/dotnet/core/extensions/dependency-injection/guidelines) +* [Tutorial: Use dependency injection in .NET](/dotnet/core/extensions/dependency-injection/usage) * [.NET dependency injection](/dotnet/core/extensions/dependency-injection) -* [ASP.NET CORE DEPENDENCY INJECTION: WHAT IS THE ISERVICECOLLECTION?](https://www.stevejgordon.co.uk/aspnet-core-dependency-injection-what-is-the-iservicecollection) +* [ASP.NET Core Dependecy Injection: What is the IServiceCollection?](https://www.stevejgordon.co.uk/aspnet-core-dependency-injection-what-is-the-iservicecollection) * [Four ways to dispose IDisposables in ASP.NET Core](https://andrewlock.net/four-ways-to-dispose-idisposables-in-asp-net-core/) * [Writing Clean Code in ASP.NET Core with Dependency Injection (MSDN)](/archive/msdn-magazine/2016/may/asp-net-writing-clean-code-in-asp-net-core-with-dependency-injection) * [Explicit Dependencies Principle](/dotnet/standard/modern-web-apps-azure-architecture/architectural-principles#explicit-dependencies) diff --git a/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-5-7.md b/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-5-7.md index f82a23b321b3..459936070fb7 100644 --- a/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-5-7.md +++ b/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-5-7.md @@ -99,7 +99,7 @@ The following code is generated by the Razor Pages template using individual use ## Service lifetimes -See [Service lifetimes](/dotnet/core/extensions/dependency-injection#service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Service lifetimes](/dotnet/core/extensions/dependency-injection/service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) To use scoped services in middleware, use one of the following approaches: @@ -246,15 +246,15 @@ In the preceding code: ### IDisposable guidance for Transient and shared instances -See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection-guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection/guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Default service container replacement -See [Default service container replacement](/dotnet/core/extensions/dependency-injection-guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Default service container replacement](/dotnet/core/extensions/dependency-injection/guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Recommendations -See [Recommendations](/dotnet/core/extensions/dependency-injection-guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Recommendations](/dotnet/core/extensions/dependency-injection/guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) * Avoid using the *service locator pattern*. For example, don't invoke to obtain a service instance when you can use DI instead: @@ -489,7 +489,7 @@ The following code is generated by the Razor Pages template using individual use ## Service lifetimes -See [Service lifetimes](/dotnet/core/extensions/dependency-injection#service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Service lifetimes](/dotnet/core/extensions/dependency-injection/service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) To use scoped services in middleware, use one of the following approaches: @@ -640,15 +640,15 @@ In the preceding code: ### IDisposable guidance for Transient and shared instances -See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection-guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection/guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Default service container replacement -See [Default service container replacement](/dotnet/core/extensions/dependency-injection-guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Default service container replacement](/dotnet/core/extensions/dependency-injection/guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Recommendations -See [Recommendations](/dotnet/core/extensions/dependency-injection-guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Recommendations](/dotnet/core/extensions/dependency-injection/guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) * Avoid using the *service locator pattern*. For example, don't invoke to obtain a service instance when you can use DI instead: diff --git a/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-8.md b/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-8.md index 074662e9443c..f8f79b8fd72f 100644 --- a/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-8.md +++ b/aspnetcore/fundamentals/dependency-injection/includes/dependency-injection-8.md @@ -100,7 +100,7 @@ The following code is generated by the Razor Pages template using individual acc ## Service lifetimes -See [Service lifetimes](/dotnet/core/extensions/dependency-injection#service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Service lifetimes](/dotnet/core/extensions/dependency-injection/service-lifetimes) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) To use scoped services in middleware, use one of the following approaches: @@ -252,15 +252,15 @@ In the preceding code: ### IDisposable guidance for Transient and shared instances -See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection-guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [IDisposable guidance for Transient and shared instance](/dotnet/core/extensions/dependency-injection/guidelines#idisposable-guidance-for-transient-and-shared-instances) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Default service container replacement -See [Default service container replacement](/dotnet/core/extensions/dependency-injection-guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Default service container replacement](/dotnet/core/extensions/dependency-injection/guidelines#default-service-container-replacement) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) ## Recommendations -See [Recommendations](/dotnet/core/extensions/dependency-injection-guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) +See [Recommendations](/dotnet/core/extensions/dependency-injection/guidelines#recommendations) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection) * Avoid using the *service locator pattern*. For example, don't invoke to obtain a service instance when you can use DI instead: @@ -352,9 +352,9 @@ The following table lists a small sample of these framework-registered services: * [NDC Conference Patterns for DI app development](https://www.youtube.com/watch?v=x-C-CNBVTaY) * * -* [Understand dependency injection basics in .NET](/dotnet/core/extensions/dependency-injection-basics) -* [Dependency injection guidelines](/dotnet/core/extensions/dependency-injection-guidelines) -* [Tutorial: Use dependency injection in .NET](/dotnet/core/extensions/dependency-injection-usage) +* [Understand dependency injection basics in .NET](/dotnet/core/extensions/dependency-injection/basics) +* [Dependency injection guidelines](/dotnet/core/extensions/dependency-injection/guidelines) +* [Tutorial: Use dependency injection in .NET](/dotnet/core/extensions/dependency-injection/usage) * [.NET dependency injection](/dotnet/core/extensions/dependency-injection) * [ASP.NET CORE DEPENDENCY INJECTION: WHAT IS THE ISERVICECOLLECTION?](https://www.stevejgordon.co.uk/aspnet-core-dependency-injection-what-is-the-iservicecollection) * [Four ways to dispose IDisposables in ASP.NET Core](https://andrewlock.net/four-ways-to-dispose-idisposables-in-asp-net-core/) diff --git a/aspnetcore/grpc/authn-and-authz.md b/aspnetcore/grpc/authn-and-authz.md index 1868f6440867..354930bff96b 100644 --- a/aspnetcore/grpc/authn-and-authz.md +++ b/aspnetcore/grpc/authn-and-authz.md @@ -124,7 +124,7 @@ builder.Services }); ``` -Dependency injection (DI) can be combined with `AddCallCredentials`. An overload passes `IServiceProvider` to the delegate, which can be used to get a service [constructed from DI using scoped and transient services](/dotnet/core/extensions/dependency-injection#service-lifetimes). +Dependency injection (DI) can be combined with `AddCallCredentials`. An overload passes `IServiceProvider` to the delegate, which can be used to get a service [constructed from DI using scoped and transient services](/dotnet/core/extensions/dependency-injection/service-lifetimes). Consider an app that has: @@ -393,7 +393,7 @@ services }); ``` -Dependency injection (DI) can be combined with `AddCallCredentials`. An overload passes `IServiceProvider` to the delegate, which can be used to get a service [constructed from DI using scoped and transient services](/dotnet/core/extensions/dependency-injection#service-lifetimes). +Dependency injection (DI) can be combined with `AddCallCredentials`. An overload passes `IServiceProvider` to the delegate, which can be used to get a service [constructed from DI using scoped and transient services](/dotnet/core/extensions/dependency-injection/service-lifetimes). Consider an app that has: diff --git a/aspnetcore/grpc/clientfactory.md b/aspnetcore/grpc/clientfactory.md index ba03bbec6a57..f7b368feeaaf 100644 --- a/aspnetcore/grpc/clientfactory.md +++ b/aspnetcore/grpc/clientfactory.md @@ -108,7 +108,7 @@ builder.Services .AddInterceptor(InterceptorScope.Client); ``` -Creating client scoped interceptors is useful when an interceptor requires [scoped or transient scoped services from DI](/dotnet/core/extensions/dependency-injection#service-lifetimes). +Creating client scoped interceptors is useful when an interceptor requires [scoped or transient scoped services from DI](/dotnet/core/extensions/dependency-injection/service-lifetimes). A gRPC interceptor or channel credentials can be used to send `Authorization` metadata with each request. For more information about configuring authentication, see [Send a bearer token with gRPC client factory](xref:grpc/authn-and-authz#bearer-token-with-grpc-client-factory). @@ -331,7 +331,7 @@ services .AddInterceptor(InterceptorScope.Client); ``` -Creating client scoped interceptors is useful when an interceptor requires [scoped or transient scoped services from DI](/dotnet/core/extensions/dependency-injection#service-lifetimes). +Creating client scoped interceptors is useful when an interceptor requires [scoped or transient scoped services from DI](/dotnet/core/extensions/dependency-injection/service-lifetimes). A gRPC interceptor or channel credentials can be used to send `Authorization` metadata with each request. For more information about configuring authentication, see [Send a bearer token with gRPC client factory](xref:grpc/authn-and-authz#bearer-token-with-grpc-client-factory). diff --git a/aspnetcore/security/authorization/dependencyinjection.md b/aspnetcore/security/authorization/dependencyinjection.md index fb52de15fb2e..8f6ab0513514 100644 --- a/aspnetcore/security/authorization/dependencyinjection.md +++ b/aspnetcore/security/authorization/dependencyinjection.md @@ -37,7 +37,7 @@ public class SampleAuthorizationHandler : AuthorizationHandler to register the preceding handler: +The preceding handler can be registered with any [service lifetime](/dotnet/core/extensions/dependency-injection/service-lifetimes). The following code uses to register the preceding handler: ```csharp builder.Services.AddSingleton(); @@ -78,7 +78,7 @@ public class SampleAuthorizationHandler : AuthorizationHandler to register the preceding handler: +The preceding handler can be registered with any [service lifetime](/dotnet/core/extensions/dependency-injection/service-lifetimes). The following code uses to register the preceding handler: ```csharp services.AddSingleton(); diff --git a/aspnetcore/security/authorization/policies.md b/aspnetcore/security/authorization/policies.md index ea3bdb74c917..fd9f88ecffc4 100644 --- a/aspnetcore/security/authorization/policies.md +++ b/aspnetcore/security/authorization/policies.md @@ -1,11 +1,12 @@ --- title: Policy-based authorization in ASP.NET Core +ai-usage: ai-assisted author: wadepickett description: Learn how to create and use authorization policy handlers for enforcing authorization requirements in an ASP.NET Core app. monikerRange: '>= aspnetcore-3.1' ms.author: wpickett ms.custom: mvc -ms.date: 1/5/2023 +ms.date: 02/17/2026 uid: security/authorization/policies --- # Policy-based authorization in ASP.NET Core @@ -28,7 +29,7 @@ The primary service that determines if authorization is successful is is a marker service with no methods, and the mechanism for tracking whether authorization is successful. + is a marker interface with no methods, and the mechanism for tracking whether authorization is successful. Each is responsible for checking if requirements are met: