dependency injection - Simple injector getting instance of UserStore -


this how i'm registering identity classes:

     container.registerperwebrequest<appdbcontext>();          container.registerperwebrequest<iappuserstore>(() =>             new appuserstore(container.getinstance<appdbcontext>()));          container.registerperwebrequest<appusermanager>();           container.registerperwebrequest<appsigninmanager>();          container.registerinitializer<appusermanager>(             manager => initializeusermanager(manager, app)); 

account controller:

 private readonly appsigninmanager _signinmanager;     private readonly appusermanager _usermanager;      public accountcontroller(appusermanager usermanager, appsigninmanager signinmanager )     {         _signinmanager = signinmanager;         _usermanager = usermanager;     } 

everything good, when try type

 var test = new container().getinstance<iappuserstore>(); 

i next error: no registration type iappuserstore found

but getinstance<appdbcontext> goes ok

why can't instances? container.verify() compiles without errors.

var test = new container().getinstance<iappuserstore>(); 

will fail because creating new instance of container has no registrations , therefore not know implementation (i.e. class) asking when iappuserstore (interface).

container().getinstance<appdbcontext>() 

will work because asking class , container create instance of class if not registered as long container can resolve of constructor arguments of type.

try avoid referencing container outside of composition root. if accountcontroller needs iappuserstore should consider adding constructor of accountcontroller.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -