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

Mugen Injection [Registering Bindings]

All bindings are registered with IInjectorBinder.
Bindings can be created using lambda expressions, by reflection, by method delegate, or by providing a ready-made instance.
You have two way to register binding, use method Bind or BindWithManualBuild. Methods perform the same operation, but has a different way to build. The method Bind will automatically put a binding in an IInjector, when it will be requested.
This code shows how work the Bind method:

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

//Registering dependency use a Bind method.
_injector.Bind<IWriter>().To<ConsoleWriter>();
This method is not thread-safety, because another thread may request this service when it constructing, and you can get a non-valid binding.
To resolve this situation you have to use the BindWithManualBuild method. This method will not automatically put a binding in an IInjector, you should do it.
This code shows how work the BindWithManualBuild method:
// Create your MugenInjector.
_injector = new MugenInjector();

//Registering dependency use a BindWithManualBuild method.
_injector.BindWithManualBuild<IWriter>().To<ConsoleWriter>().Build();
This method is thread-safety, because you control when it should be build.

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]