Runar Ovesen Hjerpbakk

Programmer. Software Architect. Technical Manager.

FermiContinater - a C# IoC container for the rest of us

Fermicontainer icon

What the world needs most is more IoC containers in the .Net space. Therefore I created FermiContianer, the simples IoC container imaginable.

FermiContainer supports registration of interfaces and implementing classes, and through constructor injection the dependencies known to the container are automatically resolved. No attributes or XML configuration are needed. This is simplicity at its best and FermiContainer is truly a C# IoC container for the rest of us.

See the tests for complete usage examples, or use the quick starts below.

Register registers interfaces and their implementation, or just standalone classes.

IFermiContainer fermiContainer = new FermiContainer();

fermiContainer.Register<ICalculator, Calculator>();

Resolve gives you a new instance each time. Constructor arguments are automatically resolved using the container. FermiContainer will use the first constructor if multiple constructors are present in the class.

var calculator = fermiContainer.Resolve<ICalculator>();


var calculator2 = fermiContainer.Resolve<ICalculator>();

Assert.AreNotSame(calculator, calculator2);

Unless you have already registered an existing instance.

var calculator = new Calculator();
m_fermiContainer.Register<ICalculator, Calculator>(() => calculator);

var calculator2 = m_fermiContainer.Resolve<ICalculator>();

Assert.AreSame(calculator, calculator2);

Singleton returns the same single instance each time.

var calculator = fermiContainer.Singleton<ICalculator>();

var calculator2 = fermiContainer.Singleton<ICalculator>();

Assert.AreSame(calculator, calculator2);

That's it! Available through NuGet for for .Net 4.0 or later, Xamarin.iOS, Xamarin.Mac, Xamarin.Android, Windows 8, Windows Phone 8, Windows Store apps and Silverlight 5. The source lives on GitHub.

If FermiContainer ever becomes too simple for your needs, I recommend LightInject.

PM> Install-Package FermiContainer

PM> Install-Package FermiContainer.Sources