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

Mugen Injection [Using condition for binding]

When you register service you can specify the condition for bindings, available conditions:

  • WhenInto - indicates that the binding should be used only for injections on the specified type. Types that derive from the specified type will not be considered as valid target.
  • WhenIntoIsAssignable - indicates that the binding should be used only for injections on the specified type. Types that derive from the specified type are considered as valid targets.
  • WhenNamespaceEqual - indicates that the binding should be used only for injections on the specified type when namespace equals.
  • WhenClassHasAttribute - indicates that the binding should be used only when the class being injected has an attribute of the specified type.
  • When - indicates that the binding should be used only for requests that support the specified condition.
Example of usage:
// Create your MugenInjector.
_injector = new MugenInjector();
_injector.Bind<Alpha>().ToSelf().WhenInto<Program>();
_injector.Bind<Alpha>().ToSelf().WhenIntoIsAssignable<Alpha>();
_injector.Bind<Alpha>().ToSelf().WhenClassHasAttribute<SerializableAttribute>();
_injector.Bind<Alpha>().ToSelf().WhenNamespaceEqual("Test");
_injector.Bind<Alpha>()
            .ToSelf()
            .When(context => context.TypeInto != null && context.TypeInto.FullName.StartsWith("S"));

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]