I’m having an issue with something similar. I have setup a generic repository and UoW using AutoFac…
builder.RegisterModule(new RepositoryModule());
builder.RegisterType(typeof(MyContext)).As(typeof(DbContext)).InstancePerLifetimeScope();
builder.RegisterType(typeof(UnitOfWork)).As(typeof(IUnitOfWork)).InstancePerLifetimeScope();
I have a scheduled task that runs my service object just fine, but entity framework complains when I try to save to the database…
“New transaction is not allowed because there are other threads running in the session.”
After researching, I know this is because the Hangfire process is being executing in a background thread but I am kind of lost on how to resolve that from here. Any help would be greatly appreciated.