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

Mugen Injection [Instance lifecycle]

When a request is made for a service, MugenInjector can return a single instance (SingletonScopeLifecycle), a new instance (TransientScopeLifecycle) or a single instance within some kind of context, e.g. a thread or an HTTP request.

This applies to instances returned from an explicit Resolve() call, and instances created internally by the container to satisfy the dependencies of another component.
All lifecycle scopes implements the IScopeLifecycle interface and you easily can write your implementation.
A list of all available types of scopes:

  • TransientScopeLifecycle - instances activated via the binding should not be re-used, nor have their lifecycle managed.
  • SingletonScopeLifecycle - only a single instance of the binding should be created, and then should be re-used for all subsequent requests.
  • ThreadScopeLifecycle - instances activated via the binding should be re-used within the same thread.
  • UnitOfWorkScopeLifecycle - the instance will be singleton for the duration of the unit of work. In practice this means that each IInjector will contain one unit of service.
  • WeakReferenceScopeLifecycle - instances activated via the binding should be re-used as weak reference.
  • ManagedScopeLifecycle - instances activated via the IManagedScope lifecycle managment.
  • CustomScopeLifecycle - instances activated via the custom lifecycle managment.
  • WebContextScopeLifecycle - instances activated via the binding should be re-used within the same request, for scope used HttpContext, or HttpSessionState, or OperationContext.

You can also make some IScopeLifecycle as default for all bindings if it is not explicitly, default is TransientScopeLifecycle:
// Create your MugenInjector.
_injector = new MugenInjector();
_injector.Settings.DefaultScopeLifecycleFactory = () => new UnitOfWorkScopeLifecycle();

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]