Unit of Work
Unit of work pattern used within RCommon.
var customer = new Customer { FirstName = "John", LastName = "Doe" };
var salesPerson = new SalesPerson { FirstName = "Jane", LastName = "Doe", SalesQuota = 2000 };
// Setup required services
var scopeFactory = this.ServiceProvider.GetService<IUnitOfWorkScopeFactory>();
using (var scope = scopeFactory.Create(TransactionMode.Default))
{
var customerRepo = this.ServiceProvider.GetService<IFullFeaturedRepository<Customer>>();
repo.DataStoreName = "TestDbContext";
await customerRepo.AddAsync(customer);
var salesPersonRepo = this.ServiceProvider.GetService<IFullFeaturedRepository<SalesPerson>>();
salesPersonRepo.DataStoreName = "TestDbContext";
await salesPersonRepo.AddAsync(salesPerson);
scope.Commit();
}Unit of Work in MediatR Behavior Pipeline
Last updated