Microsoft.Extensions.DependencyInjection.AutoActivation
9.8.0
Prefix Reserved
dotnet add package Microsoft.Extensions.DependencyInjection.AutoActivation --version 9.8.0
NuGet\Install-Package Microsoft.Extensions.DependencyInjection.AutoActivation -Version 9.8.0
<PackageReference Include="Microsoft.Extensions.DependencyInjection.AutoActivation" Version="9.8.0" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.AutoActivation" Version="9.8.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.AutoActivation" />
paket add Microsoft.Extensions.DependencyInjection.AutoActivation --version 9.8.0
#r "nuget: Microsoft.Extensions.DependencyInjection.AutoActivation, 9.8.0"
#:package Microsoft.Extensions.DependencyInjection.AutoActivation@9.8.0
#addin nuget:?package=Microsoft.Extensions.DependencyInjection.AutoActivation&version=9.8.0
#tool nuget:?package=Microsoft.Extensions.DependencyInjection.AutoActivation&version=9.8.0
Microsoft.Extensions.DependencyInjection.AutoActivation
This provides the ability to instantiate registered singletons during startup instead of during the first time it is used.
A singleton is typically created when it is first used, which can lead to higher than usual latency in responding to incoming requests. Creating the instances on startup helps prevent the service from exceeding its SLA for the first set of requests it processes.
Install the package
From the command-line:
dotnet add package Microsoft.Extensions.DependencyInjection.AutoActivation
Or directly in the C# project file:
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.DependencyInjection.AutoActivation" Version="[CURRENTVERSION]" />
</ItemGroup>
Usage Example
Registering Services
The services to auto-activate can be registered using the following methods:
public static IServiceCollection ActivateSingleton<TService>(this IServiceCollection services)
public static IServiceCollection ActivateSingleton(this IServiceCollection services, Type serviceType)
public static IServiceCollection AddActivatedSingleton<TService, TImplementation>(this IServiceCollection services, Func<IServiceProvider, TImplementation> implementationFactory)
public static IServiceCollection AddActivatedSingleton<TService, TImplementation>(this IServiceCollection services)
public static IServiceCollection AddActivatedSingleton<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)
public static IServiceCollection AddActivatedSingleton<TService>(this IServiceCollection services)
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType)
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
public static IServiceCollection AddActivatedSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
public static void TryAddActivatedSingleton(this IServiceCollection services, Type serviceType)
public static void TryAddActivatedSingleton(this IServiceCollection services, Type serviceType, Type implementationType)
public static void TryAddActivatedSingleton(this IServiceCollection services, Type serviceType, Func<IServiceProvider, object> implementationFactory)
public static void TryAddActivatedSingleton<TService>(this IServiceCollection services)
public static void TryAddActivatedSingleton<TService, TImplementation>(this IServiceCollection services)
public static void TryAddActivatedSingleton<TService>(this IServiceCollection services, Func<IServiceProvider, TService> implementationFactory)
public static IServiceCollection ActivateKeyedSingleton<TService>(this IServiceCollection services, object? serviceKey)
public static IServiceCollection ActivateKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey)
public static IServiceCollection AddActivatedKeyedSingleton<TService, TImplementation>(this IServiceCollection services, object? serviceKey, Func<IServiceProvider, object?, TImplementation> implementationFactory)
public static IServiceCollection AddActivatedKeyedSingleton<TService, TImplementation>(this IServiceCollection services, object? serviceKey)
public static IServiceCollection AddActivatedKeyedSingleton<TService>(this IServiceCollection services, object? serviceKey, Func<IServiceProvider, object?, TService> implementationFactory)
public static IServiceCollection AddActivatedKeyedSingleton<TService>(this IServiceCollection services, object? serviceKey)
public static IServiceCollection AddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey)
public static IServiceCollection AddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey, Func<IServiceProvider, object?, object> implementationFactory)
public static IServiceCollection AddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey, Type implementationType)
public static void TryAddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey)
public static void TryAddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey, Type implementationType)
public static void TryAddActivatedKeyedSingleton(this IServiceCollection services, Type serviceType, object? serviceKey, Func<IServiceProvider, object?, object> implementationFactory)
public static void TryAddActivatedKeyedSingleton<TService>(this IServiceCollection services, object? serviceKey)
public static void TryAddActivatedKeyedSingleton<TService, TImplementation>(this IServiceCollection services, object? serviceKey)
public static void TryAddActivatedKeyedSingleton<TService>(this IServiceCollection services, object? serviceKey, Func<IServiceProvider, object?, TService> implementationFactory)
For example:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddActivatedSingleton<MyService>();
var app = builder.Build();
app.Run();
public class MyService
{
public MyService()
{
Console.WriteLine("MyService is created");
}
}
Result:
MyService is created
info: Microsoft.Hosting.Lifetime[14]
Now listening on: http://localhost:5297
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
Services that are already registered can also be auto-activated:
builder.Services.AddSingleton<OtherService>();
// ...
builder.Services.ActivateSingleton<OtherService>();
Feedback & Contributing
We welcome feedback and contributions in our GitHub repo.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 is compatible. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETFramework 4.6.2
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
-
.NETStandard 2.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
-
net8.0
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
-
net9.0
- Microsoft.Extensions.Hosting.Abstractions (>= 9.0.8)
NuGet packages (17)
Showing the top 5 NuGet packages that depend on Microsoft.Extensions.DependencyInjection.AutoActivation:
Package | Downloads |
---|---|
Microsoft.Extensions.Telemetry
Provides canonical implementations of telemetry abstractions. |
|
Microsoft.Extensions.Diagnostics.ResourceMonitoring
Measures processor and memory usage. |
|
Microsoft.AspNetCore.Diagnostics.Middleware
ASP.NET Core middleware for collecting high-quality telemetry. |
|
Microsoft.Extensions.AsyncState
Asynchronous feature store. |
|
Kurrent.Surge.DataProtection
Package Description |
GitHub repositories (2)
Showing the top 2 popular GitHub repositories that depend on Microsoft.Extensions.DependencyInjection.AutoActivation:
Repository | Stars |
---|---|
microsoft/WhatTheHack
A collection of challenge based hack-a-thons including student guide, coach guide, lecture presentations, sample/instructional code and templates. Please visit the What The Hack website at: https://aka.ms/wth
|
|
Azure/Vector-Search-AI-Assistant
Microsoft Official Build Modern AI Apps reference solutions and content. Demonstrate how to build Copilot applications that incorporate Hero Azure Services including Azure OpenAI Service, Azure Container Apps (or AKS) and Azure Cosmos DB for NoSQL with Vector Search.
|
Version | Downloads | Last Updated |
---|---|---|
9.8.0 | 9,668 | 8/12/2025 |
9.7.0 | 375,559 | 7/8/2025 |
9.6.0 | 918,128 | 6/10/2025 |
9.5.0 | 1,061,772 | 5/13/2025 |
9.4.0 | 1,681,164 | 4/8/2025 |
9.3.0 | 1,272,309 | 3/11/2025 |
9.2.0 | 1,868,584 | 2/11/2025 |
9.1.0 | 1,102,826 | 1/14/2025 |
9.0.0 | 3,181,388 | 11/12/2024 |
9.0.0-preview.9.24507.7 | 111,690 | 10/8/2024 |
9.0.0-preview.8.24460.1 | 36,102 | 9/10/2024 |
9.0.0-preview.7.24412.10 | 7,852 | 8/14/2024 |
9.0.0-preview.6.24353.1 | 5,162 | 7/10/2024 |
9.0.0-preview.5.24311.7 | 9,458 | 6/11/2024 |
9.0.0-preview.4.24271.2 | 11,573 | 5/21/2024 |
9.0.0-preview.3.24209.3 | 9,924 | 4/11/2024 |
9.0.0-preview.2.24157.4 | 3,850 | 3/12/2024 |
9.0.0-preview.1.24108.1 | 2,287 | 2/13/2024 |
8.10.0 | 6,543,639 | 10/8/2024 |
8.9.1 | 1,670,512 | 9/6/2024 |
8.9.0 | 73,866 | 9/5/2024 |
8.8.0 | 1,038,571 | 8/13/2024 |
8.7.0 | 1,771,966 | 7/10/2024 |
8.6.0 | 1,079,790 | 6/11/2024 |
8.5.0 | 1,853,890 | 5/14/2024 |
8.4.0 | 2,605,104 | 4/9/2024 |
8.3.0 | 796,047 | 3/12/2024 |
8.2.0 | 1,422,694 | 2/13/2024 |
8.1.0 | 700,181 | 1/9/2024 |
8.0.0 | 1,836,394 | 11/14/2023 |
8.0.0-rc.2.23510.2 | 6,328 | 10/10/2023 |
8.0.0-rc.1.23453.1 | 1,903 | 9/12/2023 |
8.0.0-preview.7.23407.5 | 1,596 | 8/8/2023 |
8.0.0-preview.6.23360.2 | 877 | 7/12/2023 |
8.0.0-preview.5.23308.3 | 4,215 | 6/14/2023 |
8.0.0-preview.4.23273.7 | 4,360 | 5/23/2023 |