![]() |
VOOZH | about |
dotnet add package Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection --version 1.8.0
NuGet\Install-Package Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection -Version 1.8.0
<PackageReference Include="Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection" Version="1.8.0" />
<PackageVersion Include="Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection" Version="1.8.0" />Directory.Packages.props
<PackageReference Include="Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection" />Project file
paket add Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection --version 1.8.0
#r "nuget: Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection, 1.8.0"
#:package Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection@1.8.0
#addin nuget:?package=Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection&version=1.8.0Install as a Cake Addin
#tool nuget:?package=Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection&version=1.8.0Install as a Cake Tool
Decouples users and frameworks (that are based on Simplify.DI) from dependency on IOC containers. Instead of that, they will only depend on Simplify.DI interface.
Disciplines and unifies dependencies registration, verification, and objects creation.
Provides DIContainer.Current ambient context as a centralized IOC container.
Provides a unified interface for creating IOC container providers (wrappers) for IOC container frameworks.
Using DIContainer.Current and respective container provider, you can switch between any IOC container without rewriting your code or changing IOC container behavior.
Also, as a centralized IOC container, you can use it for building, for example, some framework which needs to use constructor injection and at the same time use it by that framework user.
Available at NuGet as binary package
By default, DIContainer.Current is initialized with DryIocDIProvider container provider (DryIOC).
Other container providers available:
Please create an issue if you want another container provider.
Main IOC container interface is IDIContainerProvider
public interface IFoo
{
}
public class Foo : IFoo
{
public Foo(IBar bar)
{
}
}
public class Foo2 : IFoo
{
public Foo2(IBar bar, string someParameter)
{
}
}
public interface IBar
{
}
public class Bar : IBar
{
}
public class Bar2 : IBar
{
public Bar2(string someParameter)
{
}
}
// Simple registration
DIContainer.Current.Register<IBar, Bar>()
.Register<IFoo, Foo>();
// Registration with delegate
DIContainer.Current.Register<IBar>(p => new Bar2("test"));
// Registration with delegate and type resolve
DIContainer.Current.Register<IFoo>(p => new Foo2(p.Resolve<IBar>(), "test"));
var myObj = DIContainer.Current.Resolve<IBar>();
Container verification is a process of building registered objects graph and checking what all required types are present in a container and there is no registrations lifetime mismatches
DIContainer.Current.Verify();
In case of any container mismatches an exception will be thrown, exact type of the exception and messages will depend on current container provider
3 type of scopes available:
// Simple registration
DIContainer.Current.Register<IBar, Bar>(LifetimeType.PerLifetimeScope);
// Any dependency while registration with delegate should be resolved with delegate parameter `p`, it is current scope resolve provider.
DIContainer.Current.Register<IFoo>(p => new Foo2(p.Resolve<IBar>(), "Test"), LifetimeType.PerLifetimeScope);
// Note, what scope.Container actually it is the same container as DIContainer.Current, for example, if using SimpleInjector, but with DryIoc it will be child container.
using (var scope = DIContainer.Current.BeginLifetimeScope())
{
var myObject = scope.Resolver.Resolve<IFoo>();
}
You can use any IOC container to directly register types or perform specific actions, for example, with Simple Injector:
var provider = new SimpleInjectorDIProvider();
DIContainer.Current = provider;
provider.Container.RegisterSingleton<IFoo>();
...
var provider = new SimpleInjectorDIProvider();
DIContainer.Current = provider;
...
DIContainer.Current.Register<IBar, Bar>();
...
provider.Container.Verify();
public static class Program
{
public static void Main(string[] args)
{
var provider = new DryIocDIProvider();
provider.RegisterAll()
.Verify();
using var scope = provider.BeginLifetimeScope();
scope.Resolver.Resolve<IMyService1>().DoWork();
}
private static IDIContainerProvider RegisterAll(this IDIContainerProvider provider)
{
provider.RegisterServicesGroup1()
.RegisterServicesGroup2();
return provider;
}
private static IDIRegistrator RegisterServicesGroup1(this IDIRegistrator registrator) => registrator
.Register<IMyService1, MyService1>()
.Register<IMyService2>(r => new MyService2("string parameter example"))
.Register<IMyService3>(r => new MyService3(r.Resolve<IMyService2>()));
private static IDIRegistrator RegisterServicesGroup2(this IDIRegistrator registrator) => registrator
.Register<IMySettings, MySettings>(LifetimeType.Singleton)
.Register<IUsersRepository, UsersRepository>()
.Register<IGroupsRepository, GroupsRepository>();
}
How to replace 'Simplify.DI.Provider.Microsoft.Extensions.DependencyInjection' internal container with container from AspNetCore application (This allows us to perform registrations via Simplify.DI keeping original container in AspNetCore application)
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 is compatible. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 is compatible. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 is compatible. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
This package is not used by any NuGet packages.
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.8.0 | 46 | 6/25/2026 |
| 1.7.0 | 308 | 6/15/2025 |
| 1.6.0 | 963 | 6/9/2024 |
| 1.5.1 | 474 | 8/1/2023 |
| 1.5.0 | 396 | 7/3/2023 |
| 1.4.3 | 1,319 | 12/15/2022 |
| 1.4.2 | 535 | 12/14/2022 |
| 1.4.1 | 620 | 10/16/2022 |
| 1.4.0 | 768 | 7/17/2021 |
| 1.3.2 | 757 | 12/10/2020 |
| 1.3.1 | 788 | 7/6/2020 |
| 1.3.0 | 724 | 5/14/2020 |
| 1.2.0 | 912 | 9/24/2019 |
| 1.1.0 | 833 | 9/13/2019 |
| 1.0.0 | 961 | 5/20/2019 |