I get into a problem when I tried to perform asynchronous operations on a database that was registered as a singleton.
I was getting the error which is solved in this question
One of the most popular options is to register the service as transient
bsc Entity Framework Core does not support multiple parallel operations being run on the same DbContext instance.
But then I'll get a new database instance every time, which won't allow me to implement a save function with bool commit = false
Example:
TransportService.SaveTransport(transportSaveDto, commit:false); DriverService.SaveDriver(driverSaveDto, commit:false);
LotService.SaveLot(lotSaveDto, commit:true);
SaveChanges() will be invoke only in SaveLot and must save all dtos, but if I will have new db instance every time - driver and transport will not be saved
First of all, how bad is it to create a new database instance every time? Does constant creation justify itself when the opportunity to perform asynchronous operations appears?
Is there no adequate way to still leave the db in singleton and get the ability to perform asynchronous operations on one database context?