About .NET, ASP.NET, MVC, C#, WPF, WCF and everything related to .NET and more.

Mugen Injection [Named bindings]

The MugenInjector supports register binding with name. Names are not necessarily unique; multiple bindings for a given service may be registered with the same name, this code shows how it work:

public class Alpha { }
public class Beta : Alpha { }
public class Bravo : Beta { }


// Create your MugenInjector.
_injector = new MugenInjector();

_injector.Bind<Alpha>().ToSelf().NamedBinding("Alpha");
_injector.Bind<Alpha>().To<Beta>().NamedBinding("Beta");
_injector.Bind<Alpha>().To<Bravo>().NamedBinding("Bravo");

var alpha = _injector.Get<Alpha>("Alpha");//Instance of Alpha.
var beta = _injector.Get<Alpha>("Beta");//Instance of Beta.
var bravo = _injector.Get<Alpha>("Bravo");//Instance of Bravo.
This code shows how register multiple bindings with the same name:
// Create your MugenInjector.
_injector = new MugenInjector();

_injector.Bind<Alpha>().ToSelf().NamedBinding("Alpha");
_injector.Bind<Alpha>().To<Beta>().NamedBinding("Alpha");
_injector.Bind<Alpha>().To<Bravo>().NamedBinding("Alpha");

var list = _injector.Get<IList<Alpha>>("Alpha");
var enumerable = _injector.GetAll<Alpha>("Alpha");

Comments
Leave a Reply
*bold*
_italics_
+underline+
* Bullet List
** Bullet List 2
# Number List
## Number List 2
{"Do not apply formatting"}
{code:language} code here {code:language}.
Supports: aspx c#, c#, c++, html, sql, xml
[url:http://www.example.com]