entity framework - MVC5 + Autofac: DbContext is being reused -


i have context registered so:

 internal class dbcontextmodule : module {     protected override void load(containerbuilder builder)     {         builder.register(ctx => new crtechentities()).instanceperlifetimescope();     } } 

controllers registered such:

builder.registercontrollers(assembly.getexecutingassembly()).instanceperlifetimescope(); 

in 1 of repositories, ask in ctor, not new context..

 if(_context.changetracker.entries().any())     _context.changetracker.entries().tolist().each(e => e.state = entitystate.detached); 

is causing sorts of issues, , don't understand why context not new one. missing here?

if want create new instance on each request use

instanceperdependency instead of instanceperlifetimescope

instanceperlifetimescope creates 1 instance each scope, if don't create scope autofac creates default scope, , use everywhere

also please note, if in asp.net project, better practice use 1 instance each request instanceperrequest

for more check here


Comments

Popular posts from this blog

php - Zend Framework / Skeleton-Application / Composer install issue -

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -