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

Mugen Injection [Relationship types]

Dependencies using the types below are interpreted specially by MugenInjection. For example, when MugenInjection is injecting a constructor parameter of type IEnumerable<IBeta> it will not look for a component that supplies IEnumerable<IBeta>. Instead, the container will find all implementations of IBeta and inject all of them.

Implicit relationship types

Relationship Type Meaning
Alpha needs Beta Beta Dependency
Alpha needs Beta at some point in the future Lazy<Beta>, CustomLazy<Beta> Delayed instantiation
Alpha needs Beta until some point in the future Managed<Beta>, CustomManaged<Beta> Controlled lifetime
Alpha needs Beta until some point in the future UoW<Beta>, CustomUoW<Beta> Controlled lifetime
Alpha needs to create instances of Beta Func<Beta>, CustomFunc<Beta> Dynamic instantiation
Alpha needs to create instances of Beta with P1, P2 parameters Func<P1, P2, Beta> Dynamic instantiation with parameters
Alpha needs to create instances of Beta with special parameters Func<ISettings, Beta> Dynamic instantiation with special parameters
Alpha needs all instances of Beta IEnumerable<Beta>, IList<Beta>, List<Beta>, ICollection<Beta>, ICustomCollection<Beta> Collection
Alpha needs Beta with settings WithSettings<Beta>, WithCustomSettings<Beta> Metadata interrogation

To override this default behaviour it is still possible to register explicit implementations of these types.

Composing relationship types

Relationship types can be composed:
IEnumerable<Func<Managed<Beta>>>
Is interpreted correctly to mean:
  • All implementations, of
  • Factories, that return
  • Lifetime-controlled
  • Beta services

Custom relationship types

The custom relationship types in MugenInjection don’t force you to bind your application more tightly to MugenInjection. They give you a programming model for container configuration that is consistent with the way you write other components (vs. having to know a lot of specific container extension points and APIs that also potentially centralise your configuration.)

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]