Micro DI for netstandard
Install the SharpInjector package via Nuget:
Install-Package SharpInjector
ServiceLocator.Default.Register<IFoo>(new Foo());
ServiceLocator.Default.Register<IFoo>(() => new Foo());
You don't need to register concrete classes, they will be instanciated as transient if not found.
var foo = ServiceLocator.Default.Resolve<Foo>();
If you try to register a type twice, an exception is thrown. If you don't want this behavior but a registration replacement instead, just set the last paramenter to true:
ServiceLocator.Default.Register<IFoo>(new Foo());
ServiceLocator.Default.Register<IFoo>(new Foo2()); //throws DuplicateRegistrationException
But...
ServiceLocator.Default.Register<IFoo>(new Foo());
ServiceLocator.Default.Register<IFoo>(new Foo2(), true); //replace the registration
Enjoy!