public void Dispose(IResolver iocResolver) { foreach (var activeTransaction in ActiveTransactions.Values) { foreach (var attendedDbContext in activeTransaction.AttendedDbContexts) { iocResolver.Release(attendedDbContext); } activeTransaction.DbContextTransaction.Dispose(); iocResolver.Release(activeTransaction.StarterDbContext); } ActiveTransactions.Clear(); }
private DbContext GetDbContext(Dictionary <string, object> args) { var dbContextProviderType = typeof(IDbContextProvider <>).MakeGenericType((Type)args["ContextType"]); try { var dbContextProviderWrapper = _iocResolver.Resolve(dbContextProviderType); var method = dbContextProviderWrapper.GetType() .GetMethod( nameof(IDbContextProvider <BaseDbContext> .GetDbContext) ); return((DbContext)method.Invoke( dbContextProviderWrapper, null )); } catch (Exception) { throw; } finally { _iocResolver.Release(dbContextProviderType); } }
public IUnitOfWorkCompleteHandle Begin(UnitOfWorkOptions options) { options.FillDefaultsForNonProvidedOptions(_defaultOptions); var outerUow = _currentUnitOfWorkProvider.Current; if (options.Scope == TransactionScopeOption.Required && outerUow != null) { return(new InnerUnitOfWorkCompleteHandle()); } var uow = _iocResolver.Resolve <IUnitOfWork>(); uow.Completed += (sender, args) => { _currentUnitOfWorkProvider.Current = null; }; uow.Failed += (sender, args) => { _currentUnitOfWorkProvider.Current = null; }; uow.Disposed += (sender, args) => { _iocResolver.Release(uow); }; //Inherit filters from outer UOW if (outerUow != null) { options.FillOuterUowFiltersForNonProvidedOptions(outerUow.Filters.ToList()); } uow.Begin(options); _currentUnitOfWorkProvider.Current = uow; return(uow); }
public void Release(object obj) { _resolvedObjects.Remove(obj); _iocResolver.Release(obj); }