Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.
/ IoC Public archive

Minimalistic Inversion of Control Container for .Net

Notifications You must be signed in to change notification settings

pitermarx/IoC

Repository files navigation

A simple Inversion of Control Container. The instance resolution is made by Type and by name.

Project Setup

Includes a solution with a test project and two classes: IoC.Factory and IoC.Container

License

The content of this project itself is licensed under the Creative Commons Attribution 3.0 license, and the underlying source code used to format and display that content is licensed under the MIT license.

Example

// if doesn't exist, create one
var container = Factory.GetContainer("TestContainer");

// register as instanciator
container.Register(() => new MyAwesomeObject());

// register as a named instanciator
container.Register(() => new MyAwesomeObject2(), "MySpecialObject2");

// register as singleton
var myObject = new MyAwesomeObject();
container.Register(() => myObject, "MyAwesomeSingleton");

// you may register a type by interface
var myObject2 = new MyAwesomeObject();
container.Register<IMyAwesomeObject>(() => myObject2);

// Seal the container to prevent further registers
// any register will throw after this
container.Seal();

// get the registers
// the resolution is first by type and then by name
var newAwesomeObject = container.Get<MyAwesomeObject>();
var newAwesomeObject2 = container.Get<MyAwesomeObject2>("MySpecialObject2");
var sameAsMyObject = container.Get<MyAwesomeObject>("MyAwesomeSingleton");
var sameAsMyObject2 = container.Get<IMyAwesomeObject>();

// will throw KeyNotFoundException
container.Get<IMyAwesomeObject>("SomethingNotRegistered"); 
container.Get<MyAwesomeObject3>(); 

Build status

About

Minimalistic Inversion of Control Container for .Net

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages