Hi All!
I have HostedService where I inject IServiceScopeFactory.
In some method of service I call scopeFactory.CreateScope().ServiceProvider.GetRequiredService<MyDbContext>()
and save information with myDb.SaveChanges.
After that I’m create BackgroundJobs, registered as builder.Service.AddTransient(myJobType)
in Program.cs
In this new jobs I can access to new record by his Id.In Job I set JobParameter with record Id.
After this job done, I want to save information to database.
When OnStateElection ElectStateContext called I can find my record Id but when try to get record from database - is nulled. In filter I get myDbContext from scopeFactory.CreateScope().ServiceProvider.GetRequiredService<MyDbContext>()
How to resolve it?