c# - Autofac override inject -


i have following:

containerbuilder.registertype<customcontext>()                 .as<customcontext>()                 .instanceperlifetimescope(); containerbuilder.registertype<customcontext>()                 .as<basecontext>()                 .instanceperlifetimescope();  public class basecontext : dbcontext {  }  public class customcontext : basecontext { } 

what trying achieve whenever basecontext injected in constructor of service pass instance of customcontext created using containerbuilder.registertype<customcontext>().as<customcontext>().instanceperlifetimescope(); , not create new one.

currently whenever lifetime scope created have 2 instances of customcontext around.

did tried that?

containerbuilder.registertype<customcontext>()                 .as<customcontext>()                 .as<basecontext>()                 .instanceperlifetimescope(); 

Comments