/SingletonContainer

Simple IoC container only supporting singleton lifetimes

Primary LanguageC#

SingletonContainer

Simple IoC container only supporting singleton lifetimes.

Basic Usage

var builder = new ContainerBuilder();
builder.Register<Dep1>().As<IDep>();
var container = builder.Build();

var instance1 = container.Resolve<IDep>();

OfType<T>() Method

IContainer.OfType<T>() returns all registrants castable to T in instantiation order

var container = builder.Build();

foreach (var thing in container.OfType<IThing>())
{
  thing.Stuff();
}

Reverse the order for a reasonable teardown strategy.

foreach (var disposable in container.OfType<IDisposable>().Reverse())
{
  disposable.Dispose();
}