Integrate EF Core into ingestion unit of work#5615
Conversation
The `IIngestionUnitOfWork` interface is updated to `IAsyncDisposable` to properly manage asynchronous resources like `ServiceControlDbContext` and `AsyncServiceScope`. `EFIngestionUnitOfWork` now manages a dedicated `ServiceControlDbContext` instance within its own `AsyncServiceScope`, persisting changes via `SaveChangesAsync`. A new `IBodyStoragePersistence` interface is introduced for abstracting message body storage.
| var scope = serviceProvider.CreateAsyncScope(); | ||
| var dbContext = scope.ServiceProvider.GetRequiredService<ServiceControlDbContext>(); | ||
| var settings = scope.ServiceProvider.GetRequiredService<EFPersisterSettings>(); | ||
| var unitOfWork = new EFIngestionUnitOfWork(scope, dbContext, storagePersistence, settings); |
There was a problem hiding this comment.
Since you are passing the container reference into the unit of work it seems like you could just resolve everything inside it's own constructor
However I'd recommend instead passing it in as an (optional?) IDisposable since that's all it cares about. An added bonus here is that it also removes the depend on Microsoft.Extensions.DI and makes testing it not require a container.
There was a problem hiding this comment.
Good idea, I'll do this in the next PR
|
|
||
| using System.IO; | ||
|
|
||
| public class MessageBodyFileResult |
There was a problem hiding this comment.
Use the 'required' modifier for the props?
| public async ValueTask DisposeAsync() | ||
| { | ||
| // Nothing to dispose yet | ||
| await dbContext.DisposeAsync(); |
There was a problem hiding this comment.
'scope.dispose' on the next line should already take care of dbcontext
There was a problem hiding this comment.
If this comment is implemented then you don't actually know that anymore
The
IIngestionUnitOfWorkinterface is updated toIAsyncDisposableto properly manage asynchronous resources likeServiceControlDbContextandAsyncServiceScope.EFIngestionUnitOfWorknow manages a dedicatedServiceControlDbContextinstance within its ownAsyncServiceScope, persisting changes viaSaveChangesAsync. A newIBodyStoragePersistenceinterface is introduced for abstracting message body storage.