Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class EntityService : IEntityService
- {
- public EntityService(
- IUnitOfWorkFactory unitOfWorkFactory,
- IRepository<Entity> repository,
- IRepository<Entity2> repository2
- )
- {
- this._unitOfWorkFactory = unitOfWorkFactory;
- //... same for other dependencies
- }
- public Entity[] GetItDone()
- {
- using (var uow = _unitOfWorkFactory.Create())
- {
- var entities = _entityRepository
- .GetAllAsQueryable(...)
- .OrderByDescending(..)
- .ThenByDescending(..)
- .ToArray();
- //... logic
- _repository.Update(...);
- //... logic
- // logic with repo2
- _repository2.Update(...);
- _repository2.Create(...);
- //... other logic with repoX
- // until this line the Unit Of Work as a whole :
- // 1. Get this entity
- // 2. Modify this if that and then create another if whatever
- // 3. Send email to a@a.com or whatever
- // 4. Consider the unit of work to be done by definition.
- // If something explodes until this row nothing will be commited to database and the work van be retried.
- // Consider it finished
- uow.Commit(); // internally calls dbcontext.SaveChanges in case you are using EF.
- }
- return entities;
- }
- public interface IUnitOfWork : IDisposable
- {
- void Commit();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement