Skip to content
Anders Malmgren edited this page Oct 20, 2015 · 6 revisions

Welcome to the DuoCode.SimpleInjector wiki!

DuoCode.SimpleInjector is a small light weight Dep.injector for DuoCode projects.

var container = new Container();
container.Bind<IMyClass, MyClass>();

instance = container.Get<IMyClass>();

That's all you need to get started. SimpleInjector also supports constructor injection so that your types do not need to know about the container.

IMPORTANT: You need to set CompilerOptions(ReflectionLevel = ReflectionLevel.Full) either on entire assembly, namespace or class for DuoCode to be able todo constructor injection

You can also register constants like

var container = new Container();
container.Bind<IMyClass>(new MyClass());

Or singleton scopes like

var container = new Container();
container.Bind<IMyClass, MyClass>()
.InSingletonScope();

You can also bind one interface to multiple concrete types like

var container = new Container();
container.Bind<IMyClass, MyClass>();
container.Bind<IMyClass, MyOtherClass>();

instance = container.GetAll<IMyClass>();

You can also get them by constructor injection

public class Foo
{
   public Foo(IEnumerable<IMyClass> instances) {}
}

You can also use auto factories from constructors like

public class Foo
{
   public Foo(Func<IMyClass> factory) 
   {
      this.instance = factory();
   }
}

You can also use open generic types

var container = new Container();
container.Bind(typeof(IMyGenericType<>), typeof(MyGenericType<>));
instance = container.Get<IMyGenericType<string>>();

On the list of things to support

  • Child containers

Clone this wiki locally