dependency injection - Register a list of implementations with Pico Container -


i have interface

public interface iinterface{} 

and have list of implementations of interface:

public class myclass1 implements iinterface{} public class myclass2 implements iinterface{} 

what i'd pico container:

  1. register implementations of iinterface able resolve them list:

    public class mytest {     public mytest(iinterface[] list){} } 
  2. and option able register implementation named key:

    container.addcomponent(iinterface.class, myclass1.class, "name1"); container.addcomponent(iinterface.class, myclass2.class, "name2"); 

    to able like:

    container.getcomponent(iinterface.class, "name2"); 

is there built-in solution @ least 1st question?

upd

  1. found implementation in pico quite strange , not intuitive.

to able inject array it's necessary:

container.addcomponent(myclass1.class); container.addcomponent(myclass2.class); container.addcomponent(mytest.class); mytest test = container.getcomponent(mytest.class); 

this inject array of implementations. behavior unclear , not intuitive. me better register pairs.

1st part works described. register number of implementations in usual way, can injected array (does not require injection params) or collection. can see example array in sample project // serverregistrar, apppico

for 2nd part there're several built in solutions e.g. using named annotations (just in guice) disapprove. or using injection parameters (which close expectations). or using custom approach can explain in details, if want.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -