c# - Can I build 2 IServiceProvider and they work together (.net core ) -


    iservicecollection serviceconfiguration = configureservices();            iserviceprovider serviceprovider = serviceconfiguration.buildserviceprovider();     ibuscontrol buscontrol = createservicebus(serviceprovider);      iservicecollection services = new servicecollection();     services.addsingleton<ibuscontrol>(buscontrol);           iserviceprovider servicebus = services.buildserviceprovider(); 

is possible this, need because createservicebus using first iserviceprovider, using dependancy injection why need 2 iserviceprovider because after want register buscontrol ibuscontrol

you can create factory method , warm in startup.cs.

services.addsingleton<ibuscontrol>(provider => createservicebus(provider)); 

and "warm" in configure method

public void configure(iappbuilder app, ibuscontrol bus) { } 

or

public void configure(iappbuilder app, ibuscontrol bus) {     app.services.getrequriedservice<ibuscontrol>(); } 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -