BitzArt.TransientServiceProvider
1.4.1
Prefix Reserved
dotnet add package BitzArt.TransientServiceProvider --version 1.4.1
NuGet\Install-Package BitzArt.TransientServiceProvider -Version 1.4.1
<PackageReference Include="BitzArt.TransientServiceProvider" Version="1.4.1" />
<PackageVersion Include="BitzArt.TransientServiceProvider" Version="1.4.1" />
<PackageReference Include="BitzArt.TransientServiceProvider" />
paket add BitzArt.TransientServiceProvider --version 1.4.1
#r "nuget: BitzArt.TransientServiceProvider, 1.4.1"
#:package BitzArt.TransientServiceProvider@1.4.1
#addin nuget:?package=BitzArt.TransientServiceProvider&version=1.4.1
#tool nuget:?package=BitzArt.TransientServiceProvider&version=1.4.1
Overview
BitzArt.DependencyInjection.TransientServiceProvider is a NuGet package that allows the creation of transient service providers - each with its own set of services. Transient service providers are isolated from each other and from the default service provider.
How it Works
1. Install
You can install the package via NuGet using the following command:
dotnet add package BitzArt.DependencyInjection.TransientServiceProvider
2. Configure
Add transient service provider factory to your service collection:
services.AddTransientServiceProvider(serviceCollection =>
{
// Add services to the serviceCollection here.
});
3. Resolve
Once the configuration is complete, you can resolve ITransientServiceProvider
- either directly from the root service provider
var transient = serviceProvider.GetRequiredService<ITransientServiceProvider>();
- or by injecting it into one of your classes
public class MyService(ITransientServiceProvider transientServiceProvider)
{
// ...
}
4. Use
Use the resolved ITransientServiceProvider similarly to how you would use a normal IServiceProvider
var myTransientService = transientServiceProvider.GetService<MyService>();
4.1. Use FallbackToGlobal flag
You can use the FallbackToGlobal flag in the options configuration and inject dependencies directly.
If this FallbackToGlobal flag is enabled in the configuration, the system will first attempt to obtain the dependency from the ITransientServiceProvider container. This is useful when you need to override or isolate certain services in a specific context, for example, for testing or performing specific tasks.
If the required dependency is not found in ITransientServiceProvider and the FallbackToGlobal flag is enabled, the search will continue in the global default container.
You can find a configuration example in the Startup file of the BitzArt.TransientServiceProvider.XUnitDependencyInjectionTests project.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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 is compatible. 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. |
-
net10.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
-
net9.0
- Microsoft.Extensions.DependencyInjection (>= 10.0.0)
- Microsoft.Extensions.Hosting.Abstractions (>= 10.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.