I'm using Autofac to inject the dependencies, my application needs to work on the backend, I'm using Quartz to trigger background workers.
I use the following code:
builder.RegisterType<AppContext>()
.AsSelf().InstancePerDependency()
allowing every worker process (thread) to have a new instance of the DbContext class, I'm doing this because the DbContext class is not thread safe.
The real problem starts when I go to update or create something it says
Object was not found in the ObjectStateManager
I've seen some solutions for that like detaching and attaching the entity. But in my case, my repository methods are being used by the frontend (Asp.Net MVC). and I don't want to replicate those methods, one specific for DB call from the web app and one from background worker.
Any solution?