c# - SimpleInjector lifestyle.CreateInstance per webrequest -


i trying register dbcontext implements 2 interfaces web application. want create webrequestlifestyle registration, simple iinjector exception on load torn registration (i think getting multiple instances didn't mind). following this example documentation, error lifestyle mismatch. when lifestyle.createregistration in on webrequestlifestyle instance, transient context registration.

question: how lifestyle.createregistration return me per web request registration rather transient registration?

edit

namespace siproject.sample.web.controllers { public class taxonomy{     public int taxonomyid { get; set; }     public string term { get; set; } }  public class navitem {     public int navitemid { get; set; }     public string navname { get; set; }     public string url { get; set; } }  public interface itaxonomydbcontext {     dbset<taxonomy> taxonomys { get; set; } }  public interface inavigationdbcontext {     dbset<navitem> navitems { get; set; }  }  public class mydbcontext : identitydbcontext, itaxonomydbcontext, inavigationdbcontext {     public dbset<taxonomy> taxonomys { get; set; }     public dbset<navitem> navitems { get; set; } }  public class myservice {      public myservice(mydbcontext dbcontext)     {      } }  public class serviceb {     public serviceb(mydbcontext dbcontext)     {      } } } 

and global.asax

    public class mvcapplication : system.web.httpapplication {     protected void application_start()     {         registerservices();         arearegistration.registerallareas();         routeconfig.registerroutes(routetable.routes);     }      private void registerservices()     {         container container = new container();          container.options.defaultscopedlifestyle = new webrequestlifestyle();          container.register<itaxonomydbcontext, mydbcontext>(lifestyle.scoped);         container.register<inavigationdbcontext, mydbcontext>(lifestyle.scoped);           container.verify();     } } 

what correct way register dbcontext single dbcontext across services?

my brain woke morning , realised mistake

here answer reference:

private void registerservices() {     container container = new container();     container.options.defaultscopedlifestyle = new webrequestlifestyle();      var registration = container.options.defaultscopedlifestyle.createregistration<mydbcontext>(container);      container.addregistration(typeof(itaxonomydbcontext), registration);     container.addregistration(typeof(inavigationdbcontext), registration);      dependencyresolver.setresolver(new simpleinjectordependencyresolver(container));      container.verify(); } 

Comments

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -