DI - multiple matches when specifying interface and entity

Posts   
 
    
JRR avatar
JRR
User
Posts: 125
Joined: 07-Dec-2005
# Posted on: 14-Jan-2009 23:39:41   

How does the Dependency Injection Framework handle multiple matches for EntityTypes?

This auditor works across all of my entities that implement ITraceableEntity:

    [DependencyInjectionInfo(typeof(ITraceableEntity), "AuditorToUse")]
    [Serializable]
    public class AuditorBase2 : AuditorBase

However, there is an entity (foo) that requires additional control when audited. Now foo happens to implement ITraceableEntity as well.

If I make another auditor class:


    [DependencyInjectionInfo(typeof(fooEntity), "AuditorToUse")]
    [Serializable]
    public class fooAuditor : AuditorBase 

Which auditor object will foo get? AuditorBase2 or fooAuditor? Or will I get a runtime error simple_smile

Perhaps I should have foo drop the ITraceableEntity interface then. What's my best solution at this point?

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 15-Jan-2009 05:17:30   

Which auditor object will foo get? AuditorBase2 or fooAuditor? Or will I get a runtime error

The auditor injected will be fooAuditor, as at the DI process takes precedence on absolute types over interfaces. So, it works something like: 1. Injects to absolute types (FooEntity) 2. If the property (Auditor) isn't already taken, then try to inject to interfaces (ITraceableEntity).

David Elizondo | LLBLGen Support Team
JRR avatar
JRR
User
Posts: 125
Joined: 07-Dec-2005
# Posted on: 15-Jan-2009 05:33:59   

Great!smile

I was hoping for that result. Thanks for the quick answer!