Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions aspnetcore/fundamentals/dependency-injection.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ For Blazor DI guidance, which adds to or supersedes the guidance in this article

For information specific to dependency injection within MVC controllers, see <xref:mvc/controllers/dependency-injection>.

For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For information on dependency injection of options, see <xref:fundamentals/configuration/options>.

This article provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
This article provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

[View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/dependency-injection/samples) ([how to download](xref:fundamentals/index#how-to-download-a-sample))

Expand Down Expand Up @@ -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/overview).

To use scoped services in middleware, use one of the following approaches:

Expand All @@ -120,9 +120,9 @@ For more information, see <xref:fundamentals/middleware/write#per-request-middle

## Service registration methods

See [Service registration](/dotnet/core/extensions/dependency-injection/service-registration) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Service registration](/dotnet/core/extensions/dependency-injection/service-registration) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).
It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).

Registering a service with only an implementation type is equivalent to registering that service with the same implementation and service type. This is why multiple implementations of a service can't be registered using the methods that don't take an explicit service type. These methods can register multiple *instances* of a service, but they all have the same *implementation* type.

Expand Down Expand Up @@ -162,7 +162,7 @@ For more information on creating middleware, see <xref:fundamentals/middleware/w

## Constructor injection behavior

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

## Entity Framework contexts

Expand Down Expand Up @@ -212,7 +212,7 @@ The following code shows how to resolve a scoped service for a limited duration

## Scope validation

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For more information, see [Scope validation](xref:fundamentals/host/web-host#scope-validation).

Expand Down Expand Up @@ -270,15 +270,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/overview).

## 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/overview).

## 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/overview).

* Avoid using the *service locator pattern*. For example, don't invoke <xref:System.IServiceProvider.GetService%2A> to obtain a service instance when you can use DI instead:

Expand Down Expand Up @@ -352,8 +352,8 @@ The following table lists a small sample of these framework-registered services:
* [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 Dependecy Injection: What is the IServiceCollection?](https://www.stevejgordon.co.uk/aspnet-core-dependency-injection-what-is-the-iservicecollection)
* [.NET dependency injection](/dotnet/core/extensions/dependency-injection/overview)
* [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/)
* [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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ ASP.NET Core supports the dependency injection (DI) software design pattern, whi

For more information specific to dependency injection within MVC controllers, see <xref:mvc/controllers/dependency-injection>.

For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For more information on dependency injection of options, see <xref:fundamentals/configuration/options>.

This topic provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
This topic provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

[View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/dependency-injection/samples) ([how to download](xref:fundamentals/index#how-to-download-a-sample))

Expand Down Expand Up @@ -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/overview).

To use scoped services in middleware, use one of the following approaches:

Expand All @@ -110,9 +110,9 @@ For more information, see <xref:fundamentals/middleware/write#per-request-middle

## Service registration methods

See [Service registration methods](/dotnet/core/extensions/dependency-injection#service-registration-methods) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Service registration methods](/dotnet/core/extensions/dependency-injection/service-registration#registration-methods) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).
It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).

Registering a service with only an implementation type is equivalent to registering that service with the same implementation and service type. This is why multiple implementations of a service cannot be registered using the methods that don't take an explicit service type. These methods can register multiple *instances* of a service, but they will all have the same *implementation* type.

Expand All @@ -138,7 +138,7 @@ public class MyService

## Constructor injection behavior

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

## Entity Framework contexts

Expand Down Expand Up @@ -188,7 +188,7 @@ The following code shows how to resolve a scoped service for a limited duration

## Scope validation

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For more information, see [Scope validation](xref:fundamentals/host/web-host#scope-validation).

Expand Down Expand Up @@ -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/overview).

## 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/overview).

## 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/overview).

* Avoid using the *service locator pattern*. For example, don't invoke <xref:System.IServiceProvider.GetService%2A> to obtain a service instance when you can use DI instead:

Expand Down Expand Up @@ -362,11 +362,11 @@ ASP.NET Core supports the dependency injection (DI) software design pattern, whi

For more information specific to dependency injection within MVC controllers, see <xref:mvc/controllers/dependency-injection>.

For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
For information on using dependency injection in applications other than web apps, see [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For more information on dependency injection of options, see <xref:fundamentals/configuration/options>.

This topic provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection).
This topic provides information on dependency injection in ASP.NET Core. The primary documentation on using dependency injection is contained in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

[View or download sample code](https://github.com/dotnet/AspNetCore.Docs/tree/main/aspnetcore/fundamentals/dependency-injection/samples) ([how to download](xref:fundamentals/index#how-to-download-a-sample))

Expand Down Expand Up @@ -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/overview).

To use scoped services in middleware, use one of the following approaches:

Expand All @@ -500,9 +500,9 @@ For more information, see <xref:fundamentals/middleware/write#per-request-middle

## Service registration methods

See [Service registration methods](/dotnet/core/extensions/dependency-injection#service-registration-methods) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Service registration methods](/dotnet/core/extensions/dependency-injection/service-registration#registration-methods) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).
It's common to use multiple implementations when [mocking types for testing](xref:test/integration-tests#inject-mock-services).

Registering a service with only an implementation type is equivalent to registering that service with the same implementation and service type. This is why multiple implementations of a service cannot be registered using the methods that don't take an explicit service type. These methods can register multiple *instances* of a service, but they will all have the same *implementation* type.

Expand All @@ -528,7 +528,7 @@ public class MyService

## Constructor injection behavior

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

## Entity Framework contexts

Expand Down Expand Up @@ -582,7 +582,7 @@ The following example shows how to access the scoped `IMyDependency` service and

## Scope validation

See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection)
See [Constructor injection behavior](/dotnet/core/extensions/dependency-injection/overview#constructor-injection-behavior) in [Dependency injection in .NET](/dotnet/core/extensions/dependency-injection/overview).

For more information, see [Scope validation](xref:fundamentals/host/web-host#scope-validation).

Expand Down Expand Up @@ -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/overview).

## 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/overview).

## 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/overview).

* Avoid using the *service locator pattern*. For example, don't invoke <xref:System.IServiceProvider.GetService%2A> to obtain a service instance when you can use DI instead:

Expand Down
Loading
Loading