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

Mugen Injection [CustomScopeLifecycle]

CustomScopeLifecycle - instances activated via the custom lifecycle managment. It use the CustomScopeDelegate or IScopeLifecycle to lifecycle management.
Example of usage CustomScopeDelegate:

// Create your MugenInjector.
_injector = new MugenInjector();
var alpha1 = _injector.Get<Alpha>();
// This is a different instance.
var alpha2 = _injector.Get<Alpha>();

/// <summary>
/// Implements the transient scope lifecycle, on the each request returns new instance of service.
/// </summary>
/// <param name="scopeLifecycleContext">The specifeid <see cref="IScopeLifecycleContext"/>.</param>
/// <returns>An instance of <see cref="object"/>.</returns>
private static object CustomScopeDelegate(IScopeLifecycleContext scopeLifecycleContext)
    return scopeLifecycleContext.ResolveCurrentService();
Example of usage IScopeLifecycle:
// Create your MugenInjector.
_injector = new MugenInjector();
_injector.Bind<Alpha>().ToSelf().InScope(new SingletonScopeLifecycle());
var alpha1 = _injector.Get<Alpha>();
// This is a same instance that alpha1.
var alpha2 = _injector.Get<Alpha>();

Leave a Reply
* 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