Skip to content

Commit f9dc4b7

Browse files
authored
Merge pull request #51306 from dotnet/main
Merge main into live
2 parents fbc39e4 + 32658e4 commit f9dc4b7

128 files changed

Lines changed: 1202 additions & 1026 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.openpublishing.redirection.core.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,22 @@
769769
"source_path_from_root": "/docs/core/extensions/culture-insensitive-string-operations.md",
770770
"redirect_url": "/dotnet/core/extensions/performing-culture-insensitive-string-operations"
771771
},
772+
{
773+
"source_path_from_root": "/docs/core/extensions/dependency-injection.md",
774+
"redirect_url": "/dotnet/core/extensions/dependency-injection/overview"
775+
},
776+
{
777+
"source_path_from_root": "/docs/core/extensions/dependency-injection-basics.md",
778+
"redirect_url": "/dotnet/core/extensions/dependency-injection/basics"
779+
},
780+
{
781+
"source_path_from_root": "/docs/core/extensions/dependency-injection-guidelines.md",
782+
"redirect_url": "/dotnet/core/extensions/dependency-injection/guidelines"
783+
},
784+
{
785+
"source_path_from_root": "/docs/core/extensions/dependency-injection-usage.md",
786+
"redirect_url": "/dotnet/core/extensions/dependency-injection/usage"
787+
},
772788
{
773789
"source_path_from_root": "/docs/core/getting-started.md",
774790
"redirect_url": "/dotnet/core/get-started",

docs/ai/how-to/access-data-in-functions.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ If you manually invoke an <xref:Microsoft.Extensions.AI.AIFunction> by calling <
2828

2929
- A dictionary of named arguments.
3030
- <xref:Microsoft.Extensions.AI.AIFunctionArguments.Context>: An arbitrary `IDictionary<object, object>` for passing additional ambient data into the function.
31-
- <xref:Microsoft.Extensions.AI.AIFunctionArguments.Services>: An <xref:System.IServiceProvider> that lets the `AIFunction` resolve arbitrary state from a [dependency injection (DI)](../../core/extensions/dependency-injection.md) container.
31+
- <xref:Microsoft.Extensions.AI.AIFunctionArguments.Services>: An <xref:System.IServiceProvider> that lets the `AIFunction` resolve arbitrary state from a [dependency injection (DI)](../../core/extensions/dependency-injection/overview.md) container.
3232

3333
If you want to access either the `AIFunctionArguments` or the `IServiceProvider` from within your <xref:Microsoft.Extensions.AI.AIFunctionFactory.Create*?displayProperty=nameWithType> delegate, create a parameter typed as `IServiceProvider` or `AIFunctionArguments`. That parameter will be bound to the relevant data from the `AIFunctionArguments` passed to `AIFunction.InvokeAsync()`.
3434

docs/ai/ichatclient.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ For scenarios where you need a different implementation for `GetResponseAsync` a
136136

137137
## Dependency injection
138138

139-
<xref:Microsoft.Extensions.AI.IChatClient> implementations are often provided to an application via [dependency injection (DI)](../core/extensions/dependency-injection.md). In the following example, an <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> is added into the DI container, as is an `IChatClient`. The registration for the `IChatClient` uses a builder that creates a pipeline containing a caching client (which then uses an `IDistributedCache` retrieved from DI) and the sample client. The injected `IChatClient` can be retrieved and used elsewhere in the app.
139+
<xref:Microsoft.Extensions.AI.IChatClient> implementations are often provided to an application via [dependency injection (DI)](../core/extensions/dependency-injection/overview.md). In the following example, an <xref:Microsoft.Extensions.Caching.Distributed.IDistributedCache> is added into the DI container, as is an `IChatClient`. The registration for the `IChatClient` uses a builder that creates a pipeline containing a caching client (which then uses an `IDistributedCache` retrieved from DI) and the sample client. The injected `IChatClient` can be retrieved and used elsewhere in the app.
140140

141141
:::code language="csharp" source="snippets/microsoft-extensions-ai/ConsoleAI.DependencyInjection/Program.cs":::
142142

docs/ai/microsoft-extensions-ai.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ For more samples, see the [dotnet/ai-samples](https://aka.ms/meai-samples) GitHu
6363

6464
- [Request a response with structured output](./quickstarts/structured-output.md)
6565
- [Build an AI chat app with .NET](./quickstarts/build-chat-app.md)
66-
- [Dependency injection in .NET](../core/extensions/dependency-injection.md)
66+
- [Dependency injection in .NET](../core/extensions/dependency-injection/overview.md)
6767
- [Caching in .NET](../core/extensions/caching.md)
6868
- [Rate limit an HTTP handler in .NET](../core/extensions/http-ratelimiter.md)

docs/architecture/maui/dependency-injection.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ private readonly IAppEnvironmentService _appEnvironmentService;
2626

2727
public ProfileViewModel(
2828
IAppEnvironmentService appEnvironmentService,
29-
IDialogService dialogService,
30-
INavigationService navigationService,
29+
IDialogService dialogService,
30+
INavigationService navigationService,
3131
ISettingsService settingsService)
3232
: base(dialogService, navigationService, settingsService)
3333
{
@@ -51,7 +51,7 @@ There are several advantages to using a dependency injection container:
5151

5252
In the context of a .NET MAUI app that uses MVVM, a dependency injection container will typically be used for registering and resolving views, registering and resolving view models, and for registering services and injecting them into view models.
5353

54-
There are many dependency injection containers available in .NET; the eShop multi-platform app uses `Microsoft.Extensions.DependencyInjection` to manage the instantiation of views, view models, and service classes in the app. `Microsoft.Extensions.DependencyInjection` facilitates building loosely coupled apps, and provides all of the features commonly found in dependency injection containers, including methods to register type mappings and object instances, resolve objects, manage object lifetimes, and inject dependent objects into constructors of objects that it resolves. For more information about `Microsoft.Extensions.DependencyInjection`, see [Dependency injection in .NET](../../core/extensions/dependency-injection.md).
54+
There are many dependency injection containers available in .NET; the eShop multi-platform app uses `Microsoft.Extensions.DependencyInjection` to manage the instantiation of views, view models, and service classes in the app. `Microsoft.Extensions.DependencyInjection` facilitates building loosely coupled apps, and provides all of the features commonly found in dependency injection containers, including methods to register type mappings and object instances, resolve objects, manage object lifetimes, and inject dependent objects into constructors of objects that it resolves. For more information about `Microsoft.Extensions.DependencyInjection`, see [Dependency injection in .NET](../../core/extensions/dependency-injection/overview.md).
5555

5656
In .NET MAUI, the `MauiProgram` class will call into the `CreateMauiApp` method to create a `MauiAppBuilder` object. The `MauiAppBuilder` object has a `Services` property of type `IServiceCollection`, which provides a place to register our components, such as views, view models, and services for dependency injection. Any components registered with the `Services` property will be provided to the dependency injection container when the `MauiAppBuilder.Build` method is called.
5757

@@ -82,7 +82,7 @@ public static class MauiProgram
8282
public static MauiApp CreateMauiApp()
8383
=> MauiApp.CreateBuilder()
8484
.UseMauiApp<App>()
85-
// Omitted for brevity
85+
// Omitted for brevity
8686
.RegisterAppServices()
8787
.RegisterViewModels()
8888
.RegisterViews()
@@ -182,7 +182,7 @@ public partial class FiltersView : ContentPage
182182
```
183183

184184
> [!TIP]
185-
> The dependency injection container is great for creating view model instances. If a view model has dependencies, it will handle the creation and injection of any required services. Just make sure that you register your view models and any dependencies that they may have with the `CreateMauiApp` method in the `MauiProgram` class.
185+
> The dependency injection container is great for creating view model instances. If a view model has dependencies, it will handle the creation and injection of any required services. Just make sure that you register your view models and any dependencies that they may have with the `CreateMauiApp` method in the `MauiProgram` class.
186186
187187
## Summary
188188

docs/azure/sdk/dependency-injection.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ ms.date: 04/25/2025
88

99
# Dependency injection with the Azure SDK for .NET
1010

11-
This article demonstrates how to register Azure service clients from the [latest Azure client libraries for .NET](https://azure.github.io/azure-sdk/releases/latest/index.html#net) for [dependency injection in a .NET app](../../core/extensions/dependency-injection.md). Every modern .NET app starts up by using the instructions provided in a *Program.cs* file.
11+
This article demonstrates how to register Azure service clients from the [latest Azure client libraries for .NET](https://azure.github.io/azure-sdk/releases/latest/index.html#net) for [dependency injection in a .NET app](../../core/extensions/dependency-injection/overview.md). Every modern .NET app starts up by using the instructions provided in a *Program.cs* file.
1212

1313
## Install packages
1414

@@ -66,7 +66,7 @@ In the preceding code:
6666

6767
## Use the registered clients
6868

69-
With the clients registered, as described in the [Register clients and subclients](#register-clients-and-subclients) section, you can now use them. In the following example, [constructor injection](../../core/extensions/dependency-injection.md#constructor-injection-behavior) is used to obtain the Blob Storage client and a factory for Service Bus sender subclients in an ASP.NET Core API controller:
69+
With the clients registered, as described in the [Register clients and subclients](#register-clients-and-subclients) section, you can now use them. In the following example, [constructor injection](../../core/extensions/dependency-injection/overview.md#constructor-injection-behavior) is used to obtain the Blob Storage client and a factory for Service Bus sender subclients in an ASP.NET Core API controller:
7070

7171
```csharp
7272
[ApiController]
@@ -75,19 +75,19 @@ public class MyApiController : ControllerBase
7575
{
7676
private readonly BlobServiceClient _blobServiceClient;
7777
private readonly ServiceBusSender _serviceBusSender;
78-
78+
7979
public MyApiController(
8080
BlobServiceClient blobServiceClient,
8181
IAzureClientFactory<ServiceBusSender> senderFactory)
8282
{
8383
_blobServiceClient = blobServiceClient;
8484
_serviceBusSender = senderFactory.CreateClient("myQueueName");
8585
}
86-
86+
8787
[HttpGet]
8888
public async Task<IEnumerable<string>> Get()
8989
{
90-
BlobContainerClient containerClient =
90+
BlobContainerClient containerClient =
9191
_blobServiceClient.GetBlobContainerClient("demo");
9292
var results = new List<string>();
9393

@@ -270,7 +270,7 @@ At some point, you may want to change the default settings for a service client.
270270
```
271271

272272
You can change the retry policy to suit your needs like so:
273-
273+
274274
```csharp
275275
builder.Services.AddAzureClients(clientBuilder =>
276276
{

docs/azure/sdk/thread-safety.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,4 @@ Further guidance for properly managing and disposing of `HttpClient` instances c
117117
## See also
118118

119119
- [Dependency injection with the Azure SDK for .NET](./dependency-injection.md)
120-
- [Dependency injection in .NET](../../core/extensions/dependency-injection.md)
120+
- [Dependency injection in .NET](../../core/extensions/dependency-injection/overview.md)

docs/azure/sdk/unit-testing-mocking.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,6 @@ Here's how it works:
263263

264264
## See also
265265

266-
* [Dependency injection in .NET](../../core/extensions/dependency-injection.md)
266+
* [Dependency injection in .NET](../../core/extensions/dependency-injection/overview.md)
267267
* [Unit testing best practices](../../core/testing/unit-testing-best-practices.md)
268268
* [Unit testing C# in .NET using dotnet test and xUnit](../../core/testing/unit-testing-csharp-with-xunit.md)

docs/core/compatibility/extensions/10.0/getkeyedservice-anykey.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Calling `GetKeyedServices()` with `KeyedService.AnyKey` returned all registratio
2121

2222
## New behavior
2323

24-
Starting in .NET 10, calling `GetKeyedService()` with `KeyedService.AnyKey` throws an <xref:System.InvalidOperationException>. This ensures that `AnyKey` can't be used to resolve a single service, as it's [intended to represent a special case](../../../extensions/dependency-injection.md#keyedserviceanykey-property) rather than a specific key.
24+
Starting in .NET 10, calling `GetKeyedService()` with `KeyedService.AnyKey` throws an <xref:System.InvalidOperationException>. This ensures that `AnyKey` can't be used to resolve a single service, as it's [intended to represent a special case](../../../extensions/dependency-injection/overview.md#keyedserviceanykey-property) rather than a specific key.
2525

2626
```csharp
2727
var service = serviceProvider.GetKeyedService(typeof(IMyService), KeyedService.AnyKey);
@@ -57,4 +57,4 @@ If you use `GetKeyedService()` or `GetKeyedServices()` with `KeyedService.AnyKey
5757

5858
## See also
5959

60-
- [Use KeyedService.AnyKey for fallbacks](../../../extensions/dependency-injection.md#keyedserviceanykey-property)
60+
- [Use KeyedService.AnyKey for fallbacks](../../../extensions/dependency-injection/overview.md#keyedserviceanykey-property)

docs/core/extensions/caching.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Since the absolute expiration (<xref:Microsoft.Extensions.Caching.Memory.MemoryC
177177

178178
## Worker Service caching
179179

180-
One common strategy for caching data, is updating the cache independently from the consuming data services. The *Worker Service* template is a great example, as the <xref:Microsoft.Extensions.Hosting.BackgroundService> runs independent (or in the background) from the other application code. When an application starts running that hosts an implementation of the <xref:Microsoft.Extensions.Hosting.IHostedService>, the corresponding implementation (in this case the `BackgroundService` or "worker") start running in the same process. These hosted services are registered with DI as singletons, through the <xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionHostedServiceExtensions.AddHostedService%60%601(Microsoft.Extensions.DependencyInjection.IServiceCollection)> extension method. Other services can be registered with DI with any [service lifetime](dependency-injection.md#service-lifetimes).
180+
One common strategy for caching data, is updating the cache independently from the consuming data services. The *Worker Service* template is a great example, as the <xref:Microsoft.Extensions.Hosting.BackgroundService> runs independent (or in the background) from the other application code. When an application starts running that hosts an implementation of the <xref:Microsoft.Extensions.Hosting.IHostedService>, the corresponding implementation (in this case the `BackgroundService` or "worker") start running in the same process. These hosted services are registered with DI as singletons, through the <xref:Microsoft.Extensions.DependencyInjection.ServiceCollectionHostedServiceExtensions.AddHostedService%60%601(Microsoft.Extensions.DependencyInjection.IServiceCollection)> extension method. Other services can be registered with DI with any [service lifetime](dependency-injection/service-lifetimes.md).
181181

182182
> [!IMPORTANT]
183183
> The service lifetime's are very important to understand. When you call <xref:Microsoft.Extensions.DependencyInjection.MemoryCacheServiceCollectionExtensions.AddMemoryCache%2A> to register all of the in-memory caching services, the services are registered as singletons.
@@ -321,7 +321,7 @@ To delete values in the distributed cache, call one of the remove APIs:
321321
322322
## See also
323323

324-
- [Dependency injection in .NET](dependency-injection.md)
324+
- [Dependency injection in .NET](dependency-injection/overview.md)
325325
- [.NET Generic Host](generic-host.md)
326326
- [Worker Services in .NET](workers.md)
327327
- [Azure for .NET developers](../../azure/index.yml)

0 commit comments

Comments
 (0)