c# - StructureMap - Register a singleton for multiple interfaces -


i want register animals singletons, wrote structure map registry following code:

this.for<ilion>.use<lion>().singleton(); this.for<ielephant>.use<elephant>().singleton(); 

ilion , ielephant derive ianimal , want possibility animals @ once. tried:

this.for<ianimal>.add<lion>().singleton(); this.for<ianimal>.add<elephant>().singleton(); 

but gives me 2 different lion instances each interface:

public anyconstructor(ilion lion, ienumerable<ianimal> animals) {     // lion == animals[0] should true here, false } 

how can tell structure map instantiate one lion?

if mean getting 2 different lion instances, can use forward<tfrom, tto>() method in registry:

this.for<ilion>().use<lion>().singleton(); this.for<ielephant>().use<elephant>().singleton(); this.forward<ilion, ianimal>(); this.forward<ielephant, ianimal>();  

then, ianimal instances use getallinstances<t>() method this:

var lion = objectfactory.getinstance<ilion>(); var elephant = objectfactory.getinstance<ielephant>(); var animal = objectfactory.getallinstances<ianimal>(); 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -