/// <summary> /// Enlists a <see cref="UnitOfWorkScope"/> instance with the transaction manager, /// with the specified transaction mode. /// </summary> /// <param name="scope">The <see cref="IUnitOfWorkScope"/> to register.</param> /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transaciton /// mode of the unit of work.</param> public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { _logger.Info(x => x("Enlisting scope {0} with transaction manager {1} with transaction mode {2}", scope.ScopeId, _transactionManagerId, mode)); var uowFactory = _scopeFactory; //Container.Resolve<IUnitOfWorkFactory>(); if (_transactions.Count == 0 || mode == TransactionMode.New || mode == TransactionMode.Supress) { _logger.Debug(x => x("Enlisting scope {0} with mode {1} requires a new TransactionScope to be created.", scope.ScopeId, mode)); var txScope = TransactionScopeHelper.CreateScope(_isolationLevel, mode); var unitOfWork = uowFactory.Create(); Guard.Against <ArgumentException>(!(unitOfWork is IExUnitOfWork), "Ошибка создания UnitOfWork: тек. объект не реализует IExUnitOfWork"); var transaction = new UnityUnitOfWorkTransaction((IExUnitOfWork)unitOfWork, txScope, _subject); transaction.TransactionDisposing += OnTransactionDisposing; transaction.EnlistScope(scope); _transactions.AddFirst(transaction); return; } CurrentTransaction.EnlistScope(scope); }
// private readonly IApprovableDomainService _approvableDomainService; // private readonly IGoodPartyAssignmentDomainService _goodPartyAssignmentDomainService; public OrderApplicationService(IOrderRepository orderRepository, IUnitOfWorkScope unitOfWorkScope, // IGoodPartyAssignmentDomainService goodPartyAssignmentDomainService, //IFuelUserRepository userRepository, IVesselInCompanyDomainService vesselDomainService, IGoodDomainService goodDomainService, IOrderFactory iOrderFactory, ICompanyDomainService companyDomainService, IOrderItemDomainService orderItemDomainService, IEntityConfigurator<Order> orderConfigurator //,IApprovableDomainService approvableDomainService ) { this.orderRepository = orderRepository; this.vesselDomainService = vesselDomainService; this.goodDomainService = goodDomainService; this.iOrderFactory = iOrderFactory; this.unitOfWorkScope = unitOfWorkScope; this.companyDomainService = companyDomainService; this.orderItemDomainService = orderItemDomainService; this.orderConfigurator = orderConfigurator; // _approvableDomainService = approvableDomainService; // _goodPartyAssignmentDomainService = goodPartyAssignmentDomainService; }
void OnScopeCommitting(IUnitOfWorkScope scope) { IncrementCommit(scope.ScopeId); if (ScopeCommitAction != null) ScopeCommitAction(scope); scope.ScopeComitting -= OnScopeCommitting; }
protected override void OnScopeCommitting(IUnitOfWorkScope scope) { Guard.Against <ObjectDisposedException>(_disposed, "The transaction attached to the scope has already been disposed."); _logger.Info(x => x("Commit signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); if (!_attachedScopes.Contains(scope)) { Dispose(); throw new InvalidOperationException("The scope being comitted is not attached to the current transaction."); } scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); if (_attachedScopes.Count == 0) { _logger.Info(x => x("All scopes have signalled a commit on transaction {0}. Flushing unit of work and comitting attached TransactionScope.", _transactionId)); try { _unitOfWork.Flush(); _transaction.Complete(); _transaction.Dispose(); ((IExUnitOfWork)_unitOfWork).AfterFlushing(); _subscriber.Next(new BusinessTransactionEvent()); _subscriber.Detach(this); } finally { Dispose(); //Dispose the transaction after comitting. } } }
public OffhireApplicationService( IOffhireFactory offhireFactory, IOffhireRepository offhireRepository, IUnitOfWorkScope unitOfWorkScope, IOffhireDomainService offhireDomainService, IEntityConfigurator<Offhire> offhireConfigurator, IVesselInCompanyDomainService vesselDomianService, IVoyageDomainService voyageDomianService, ICompanyDomainService companyDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService, ITankDomainService tankDomainService, IActivityLocationDomainService activityLocationDomainService, IOffhireManagementSystemDomainService offhireManagementSystemDomainService) { this.offhireFactory = offhireFactory; this.offhireRepository = offhireRepository; this.unitOfWorkScope = unitOfWorkScope; this.offhireDomainService = offhireDomainService; this.vesselDomianService = vesselDomianService; this.companyDomainService = companyDomainService; this.currencyDomainService = currencyDomainService; this.goodDomainService = goodDomainService; this.goodUnitDomainService = goodUnitDomainService; this.tankDomainService = tankDomainService; this.activityLocationDomainService = activityLocationDomainService; this.offhireManagementSystemDomainService = offhireManagementSystemDomainService; this.voyageDomianService = voyageDomianService; this.offhireDomainService.SetConfigurator(offhireConfigurator); }
public ReadModelBuilderQueue(IUnitOfWorkScope scope) { var connection = scope.GetRegisteredObject <SQLiteConnection>(); this.repository = new SqlRepository <ReadModelWorkItem>(connection); this.repository.Connection.CreateTable <ReadModelWorkItem>(); }
public void EndScope(IUnitOfWorkScope scope) { Guard.Against<ArgumentNullException>(scope == null, "The unit of work scope cannot be null."); _scopes.Remove(scope); scope.Dispose(); }
public IQueryable <TModel> ProjectTo <TModel, TEntity>(IQueryable <TEntity> source, params Expression <Func <TModel, object> >[] membersToExpand) { using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory)) { return(source.ProjectTo(MapperConfiguration, membersToExpand)); } }
public void MultipleThreads_MustCreateNewScopePerThread() { var unitOfWork = this.kernel.Get <IUnitOfWork>(); Guid scopeId1; Guid scopeId2 = Guid.Empty; using (IUnitOfWorkScope scope1 = unitOfWork.Start()) { scopeId1 = scope1.Id; Task otherThread = Task.Factory.StartNew(() => { using (IUnitOfWorkScope scope2 = unitOfWork.Start()) { scopeId2 = scope2.Id; } }, TaskCreationOptions.LongRunning); if (!otherThread.Wait(TimeSpan.FromSeconds(5))) { throw new TimeoutException(); } } scopeId2.Should().NotBeEmpty(); scopeId1.Should().NotBe(scopeId2); }
public static DbConnection GetConnection <TEntity>(this IUnitOfWorkScope scope) { Guard.Against <ArgumentNullException>(scope == null, "Expected a non-null IEFSession instance."); Guard.Against <ArgumentException>(!(scope is IExUnitOfWorkScope), "Не реализован интерфейс IExUnitOfWorkScope"); return(((IExUnitOfWorkScope)scope).CurrentUnitOfWork <EFUnitOfWork>().GetSession <TEntity>().Context.Connection); }
public LockUnitOfWorkScope(object syncRoot, IUnitOfWorkScopeProvider unitOfWorkScopeProvider) { #region Contracts if (syncRoot == null) throw new ArgumentNullException(); if (unitOfWorkScopeProvider == null) throw new ArgumentNullException(); #endregion // Arguments _syncRoot = syncRoot; // Enter try { // Monitor Monitor.Enter(_syncRoot); // UnitOfWorkScope _unitOfWorkScope = unitOfWorkScopeProvider.Create(); if (_unitOfWorkScope == null) throw new InvalidOperationException(); } catch { // Dispose this.Dispose(); // Throw throw; } }
public static void Flush(this IUnitOfWorkScope scope) { Guard.Against <ArgumentNullException>(scope == null, "Expected a non-null IEFSession instance."); Guard.Against <ArgumentException>(!(scope is IExUnitOfWorkScope), "Не реализован интерфейс IExUnitOfWorkScope"); ((IExUnitOfWorkScope)scope).CurrentUnitOfWork <IUnitOfWork>().Flush(); }
public AddCharterInStartReceiptVoucher(IVoucherRepository voucherRepository, IUnitOfWorkScope unitOfWorkScope ,IVoucherSetingRepository voucherSetingRepository) { _voucherRepository = voucherRepository; _unitOfWorkScope = unitOfWorkScope; _voucherSetingRepository = voucherSetingRepository; }
public static IUnitOfWorkScope WithTrackQueryORM <TEntity>(this IUnitOfWorkScope scope) { Guard.Against <ArgumentNullException>(scope == null, "Expected a non-null IEFSession instance."); Guard.Against <ArgumentException>(!(scope is IExUnitOfWorkScope), "Не реализован интерфейс IExUnitOfWorkScope"); ((IExUnitOfWorkScope)scope).SetTrackQueryORM <TEntity>(); return(scope); }
/// <summary> /// Выполнение нативного sql через контекст EF. /// </summary> /// <typeparam name="TEntity"></typeparam> /// <param name="scope"></param> /// <param name="sql"></param> /// <param name="parameters"></param> public static void ExecuteNonSql <TEntity>(this IUnitOfWorkScope scope, string sql, params object[] parameters) where TEntity : class { Guard.Against <ArgumentNullException>(scope == null, "Expected a non-null IEFSession instance."); Guard.Against <ArgumentException>(!(scope is IExUnitOfWorkScope), "Не реализован интерфейс IExUnitOfWorkScope"); ((IExUnitOfWorkScope)scope).CurrentUnitOfWork <EFUnitOfWork>().GetSession <TEntity>().Context.ExecuteStoreQuery <object>(sql, parameters); }
//private readonly ILog _logger = LogManager.GetLogger<UnitOfWorkTransaction>(); public UnitOfWorkTransaction(IUnitOfWorkScope uowScope, TransactionScope transactionScope) { CodeContract.Require(uowScope != null, "The unit of work scope was null"); CodeContract.Require(transactionScope != null, "The transaction scope was null"); _uowScope = uowScope; _transactionScope = transactionScope; }
/// <summary> /// Attaches a <see cref="UnitOfWorkScope"/> instance to the /// <see cref="UnitOfWorkTransaction"/> instance. /// </summary> /// <param name="scope">The <see cref="UnitOfWorkScope"/> instance to attach.</param> public void EnlistScope(IUnitOfWorkScope scope) { Guard.Against<ArgumentNullException>(scope == null, "Expected a non-null IUnitOfWorkScope instance."); _logger.Info(string.Format("Scope {1} enlisted with transaction {1}", scope.ScopeId, _transactionId)); _attachedScopes.Add(scope); scope.ScopeComitting += OnScopeCommitting; scope.ScopeRollingback += OnScopeRollingBack; }
protected override void OnScopeRollingBack(IUnitOfWorkScope scope) { base.OnScopeRollingBack(scope); if (_attachedScopes.IsNullOrEmpty()) { _subscriber.Detach(this); } }
/// <summary> /// Attaches a <see cref="UnitOfWorkScope"/> instance to the /// <see cref="UnitOfWorkTransaction"/> instance. /// </summary> /// <param name="scope">The <see cref="UnitOfWorkScope"/> instance to attach.</param> public void EnlistScope(IUnitOfWorkScope scope) { Guard.Against <ArgumentNullException>(scope == null, "Expected a non-null IUnitOfWorkScope instance."); _logger.Info(x => x("Scope {1} enlisted with transaction {1}", scope.ScopeId, _transactionId)); _attachedScopes.Add(scope); scope.ScopeComitting += OnScopeCommitting; scope.ScopeRollingback += OnScopeRollingBack; }
void OnScopeCommitting(IUnitOfWorkScope scope) { IncrementCommit(scope.ScopeId); if (ScopeCommitAction != null) { ScopeCommitAction(scope); } scope.ScopeComitting -= OnScopeCommitting; }
void OnScopeRollingback(IUnitOfWorkScope scope) { IncrementRollback(scope.ScopeId); if (ScopeRollbackAction != null) { ScopeRollbackAction(scope); } scope.ScopeRollingback -= OnScopeRollingback; }
protected Worker(IUnitOfWorkScope uowScope) { if (uowScope == null) { throw new ArgumentNullException(nameof(uowScope)); } UnitOfWorkScope = uowScope; }
public CharterInApplicationService(ICharterInRepository charterInRepository, ICharterInToDtoMapper charterInToDtoMapper, IUnitOfWorkScope unitOfWorkScope, IWorkflowRepository workflowRepository, ICharterOutDomainService charterOutDomainService, ICharterInDomainService charterInDomainService, IEventPublisher eventPublisher, IVesselInCompanyDomainService vesselInCompanyDomainService, IInventoryOperationNotifier inventoryOperationNotifier) { this._charterInRepository = charterInRepository; this._charterInToDtoMapper = charterInToDtoMapper; this._unitOfWorkScope = unitOfWorkScope; _charterFactory = new CharterFactory(workflowRepository, charterInDomainService, charterOutDomainService, eventPublisher, vesselInCompanyDomainService, inventoryOperationNotifier); }
/// <summary> /// Starts unit of work scope /// </summary> /// <returns>Unit of work scope</returns> public IUnitOfWorkScope Start() { IUnitOfWorkScope scope = !CurrentSessionContext.HasBind(sessionFactory) ? rootScopeFactory() : dependentScopeFactory(); //if (IsImplicitTransactionsEnabled) { scope.BeginTransaction(); } scope.BeginTransaction(); return(scope); }
internal UnitOfWorkScope(IUnitOfWorkScope unitOfWorkScope) { #region Contracts if (unitOfWorkScope == null) throw new ArgumentNullException(); #endregion // Arguments _unitOfWorkScope = unitOfWorkScope; }
/// <summary> /// Starts async unit of work scope /// </summary> /// <param name="cancellationToken">The cancellation instruction.</param> /// <returns>Unit of work scope</returns> public async Task <IUnitOfWorkScope> StartAsync(CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); IUnitOfWorkScope scope = !CurrentSessionContext.HasBind(sessionFactory) ? rootScopeFactory() : dependentScopeFactory(); await scope.BeginTransactionAsync(cancellationToken).ConfigureAwait(false); return(scope); }
public DomainCommandExecutor(IUnitOfWorkScope scope, IAggregateRegistration registration, IDomainNotificationBus eventBus) { if (eventBus == null) throw new ArgumentNullException("eventBus"); if (registration == null) throw new ArgumentNullException("registration"); if (scope == null) throw new ArgumentNullException("scope"); this.scope = scope; this.registration = registration; this.eventBus = eventBus; }
/// <summary> /// Callback executed when an enlisted scope is rolledback. /// </summary> void OnScopeRollingBack(IUnitOfWorkScope scope) { Guard.Against <ObjectDisposedException>(_disposed, "The transaction attached to the scope has already been disposed."); _logger.Info(x => x("Rollback signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); _logger.Info(x => x("Detaching all scopes and disposing of attached TransactionScope on transaction {0}", _transactionId)); scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); Dispose(); }
public FuelReportApplicationService( IUnitOfWorkScope unitOfWorkScope, ICurrencyDomainService currencyDomainService, IVoyageDomainService voyageDomainService, IFuelReportDomainService fuelReportDomainService, IApproveFlowApplicationService approveFlowApplicationService) { this.unitOfWorkScope = unitOfWorkScope; this.currencyDomainService = currencyDomainService; this.voyageDomainService = voyageDomainService; this.fuelReportDomainService = fuelReportDomainService; this.approveFlowApplicationService = approveFlowApplicationService; }
public void Logon(Guid?licenseGuid, LogonHistory history) { IUnitOfWorkScope scope = null; Account account = null; try { scope = _scopeFactory.Create(); IsValid = true; _logger.Info($"Начало запроса авторизации для {licenseGuid}"); if (!licenseGuid.HasValue) { SetError("Не определен гуид лицензии"); } else { account = _accountRepository.GetByLicenseId(licenseGuid.Value); if (account == null) { SetError($"Не найдена УЗ для {licenseGuid}"); } else { var license = account.Licenses.FirstOrDefault(l => l.Guid == licenseGuid); if (license == null) { SetError($"Не найдена лицензия по гуиду {licenseGuid}"); } else if (!license.Access) { SetError($"Для УЗ {account.Id} заблокирован доступ для лицензии {licenseGuid}"); } } } history.Account = account; _logonHistoryRepository.Save(history); scope.Commit(); _logger.Info($"Завершение запроса авторизации для {licenseGuid} и УЗ {account.Return(a=>a.Id)} и логона {history.Return(h=>h.Id)}"); } catch (Exception e) { SetError(e.ToString(), true); } finally { scope.Do(s => s.Dispose()); } }
internal UnitOfWorkScope(IUnitOfWorkScope unitOfWorkScope) { #region Contracts if (unitOfWorkScope == null) { throw new ArgumentNullException(); } #endregion // Arguments _unitOfWorkScope = unitOfWorkScope; }
public void NestedScope_MustReuseSameScope() { Guid scopeId1; Guid scopeId2; using (IUnitOfWorkScope scope1 = this.kernel.Get <IUnitOfWork>().Start()) { scopeId1 = scope1.Id; using (IUnitOfWorkScope scope2 = this.kernel.Get <IUnitOfWork>().Start()) { scopeId2 = scope2.Id; } } scopeId1.Should().Be(scopeId2); }
public void MustCreateNewScopeWhenOldOneWasDisposed() { Guid scopeId1; using (IUnitOfWorkScope scope = this.kernel.Get <IUnitOfWork>().Start()) { scopeId1 = scope.Id; } Guid scopeId2; using (IUnitOfWorkScope scope = this.kernel.Get <IUnitOfWork>().Start()) { scopeId2 = scope.Id; } scopeId1.Should().NotBe(scopeId2); }
public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false) where TModel : class, IKey <TModelKeyType> where TModelKeyType : IEquatable <TModelKeyType> where TEntity : class, IKey <TEntityKeyType> where TEntityKeyType : IEquatable <TEntityKeyType> { using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory)) { DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork; if (dbContext == null) { throw new InvalidOperationException("Unsupported Unit of Work."); } dbContext.Entry(model).State = entityState; await scope.CommitAsync(cancellationToken); } }
public OrderFacadeService(IOrderApplicationService orderAppService, ICompanyDomainService companyDomainService, IOrderToDtoMapper orderDtoMapper, IOrderItemToDtoMapper itemToDtoMapper, IOrderRepository orderRepository, IGoodUnitConvertorDomainService goodUnitConvertorDomainService, IMainUnitVlaueTomainUnitVlaueDtoMapper mainUnitVlaueTomainUnitVlaueDtoMapper , IUnitOfWorkScope unitOfWorkScope ) { _orderRepository = orderRepository; _goodUnitConvertorDomainService = goodUnitConvertorDomainService; _mainUnitVlaueTomainUnitVlaueDtoMapper = mainUnitVlaueTomainUnitVlaueDtoMapper; _unitOfWorkScope = unitOfWorkScope; _orderAppService = orderAppService; _companyDomainService = companyDomainService; _orderDtoMapper = orderDtoMapper; _itemToDtoMapper = itemToDtoMapper; }
public DomainCommandExecutor(IUnitOfWorkScope scope, IAggregateRegistration registration, IDomainNotificationBus eventBus) { if (eventBus == null) { throw new ArgumentNullException("eventBus"); } if (registration == null) { throw new ArgumentNullException("registration"); } if (scope == null) { throw new ArgumentNullException("scope"); } this.scope = scope; this.registration = registration; this.eventBus = eventBus; }
public InvoiceApplicationService(IInvoiceRepository invoiceRepository, IUnitOfWorkScope unitOfWorkScope, // IGoodPartyAssignmentDomainService goodPartyAssignmentDomainService, //IUserRepository userRepository, IVesselInCompanyDomainService vesselDomainService, IGoodDomainService goodDomainService, IInvoiceFactory invoiceFactory, ICompanyDomainService companyDomainService, IInvoiceDomainService invoiceDomainService, IInvoiceItemDomainService invoiceItemDomainService, IEffectiveFactorDomainService effectiveFactorDomainService, ICompanyRepository companyRepository //,IApprovableDomainService approvableDomainService , IOrderRepository orderRepository, IGoodRepository goodRepository, ICurrencyDomainService currencyDomainService, IInvoiceAdditionalPriceDomainService invoiceAdditionalPriceDomainService, IGoodUnitConvertorDomainService goodUnitConvertorDomainService, IBalanceDomainService balanceDomainService, IEntityConfigurator<Invoice> invoiceConfigurator) { this.invoiceRepository = invoiceRepository; this.vesselDomainService = vesselDomainService; this.goodDomainService = goodDomainService; this.invoiceFactory = invoiceFactory; this.unitOfWorkScope = unitOfWorkScope; this.companyDomainService = companyDomainService; this.invoiceDomainService = invoiceDomainService; this.invoiceItemDomainService = invoiceItemDomainService; this.effectiveFactorDomainService = effectiveFactorDomainService; this.companyRepository = companyRepository; this.orderRepository = orderRepository; this.goodRepository = goodRepository; this.currencyDomainService = currencyDomainService; this.invoiceAdditionalPriceDomainService = invoiceAdditionalPriceDomainService; this.goodUnitConvertorDomainService = goodUnitConvertorDomainService; this.balanceDomainService = balanceDomainService; this.invoiceConfigurator = invoiceConfigurator; // _approvableDomainService = approvableDomainService; // _goodPartyAssignmentDomainService = goodPartyAssignmentDomainService; }
public ApproveFlowApplicationService(IUnitOfWorkScope unitOfWorkScope, IWorkflowLogRepository workflowLogRepository, IWorkflowRepository workflowRepository, IEntityConfigurator<Order> orderConfigurator, IEntityConfigurator<FuelReport> fuelReportConfigurator, IEntityConfigurator<Scrap> scrapConfigurator, IEntityConfigurator<Charter> charterConfigurator, IEntityConfigurator<Invoice> invoiceConfigurator, IEntityConfigurator<Offhire> offhireConfigurator) { _unitOfWorkScope = unitOfWorkScope; _workflowLogRepository = workflowLogRepository; _workflowRepository = workflowRepository; this.orderConfigurator = orderConfigurator; this.fuelReportConfigurator = fuelReportConfigurator; this.scrapConfigurator = scrapConfigurator; this.invoiceConfigurator = invoiceConfigurator; this.offhireConfigurator = offhireConfigurator; this._charterConfigurator = charterConfigurator; // _approveWorkFlowFactory = approveWorkFlowFactory; // _orderApplicationService = orderApplicationService; }
public LockUnitOfWorkScope(object syncRoot, IUnitOfWorkScopeProvider unitOfWorkScopeProvider) { #region Contracts if (syncRoot == null) { throw new ArgumentNullException(); } if (unitOfWorkScopeProvider == null) { throw new ArgumentNullException(); } #endregion // Arguments _syncRoot = syncRoot; // Enter try { // Monitor Monitor.Enter(_syncRoot); // UnitOfWorkScope _unitOfWorkScope = unitOfWorkScopeProvider.Create(); if (_unitOfWorkScope == null) { throw new InvalidOperationException(); } } catch { // Dispose this.Dispose(); // Throw throw; } }
public async Task Save <TModel, TModelKeyType, TEntity, TEntityKeyType>(TModel model, CancellationToken cancellationToken, EntityState entityState, bool updateModelAfterCommit = false) where TModel : class, IKey <TModelKeyType> where TModelKeyType : IEquatable <TModelKeyType> where TEntity : class, IKey <TEntityKeyType> where TEntityKeyType : IEquatable <TEntityKeyType> { using (IUnitOfWorkScope <TUnitOfWork> scope = UnitOfWorkScopeFactory.Create(UowFactory)) { DbUnitOfWork dbContext = scope.UnitOfWork as DbUnitOfWork; if (dbContext == null) { throw new InvalidOperationException("Unsupported Unit of Work."); } var entityEntry = dbContext.ChangeTracker.Entries <TEntity>() .Where(e => !e.Entity.Id.Equals(default(TEntityKeyType))) .Where(e => typeof(TEntityKeyType) == typeof(TModelKeyType) ? e.Entity.Id.Equals(model.Id) : e.Entity.Id.ToString() == model.Id.ToString()) .SingleOrDefault(); if (entityEntry == null) { TEntity entity = Mapper.Map <TModel, TEntity>(model); entityEntry = dbContext.Entry(entity); } entityEntry.State = entityState; if (updateModelAfterCommit) { switch (entityState) { case EntityState.Added: case EntityState.Modified: dbContext.OnCommit += (db, e) => Mapper.Map(entityEntry.Entity, model); // Refresh model in case of DB-assigned values (Identity/timestamp/etc.). break; } } await scope.CommitAsync(cancellationToken); } }
/// <summary> /// Enlists a <see cref="UnitOfWorkScope"/> instance with the transaction manager, /// with the specified transaction mode. /// </summary> /// <param name="scope">The <see cref="IUnitOfWorkScope"/> to register.</param> /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transaciton /// mode of the unit of work.</param> public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { _logger.LogInformation("Enlisting scope {0} with transaction manager {1} with transaction mode {2} called from: " + new StackFrame(1).GetMethod().Name, scope.ScopeId, _transactionManagerId, mode); if (_transactions.Count == 0 || mode == TransactionMode.New || mode == TransactionMode.Supress) { _logger.LogDebug("Enlisting scope {0} with mode {1} requires a new TransactionScope to be created.", scope.ScopeId, mode); var txScope = TransactionScopeHelper.CreateScope(_logger, UnitOfWorkSettings.DefaultIsolation, mode); var unitOfWork = _unitOfWorkFactory.Create(); var transaction = new UnitOfWorkTransaction(_logger, unitOfWork, txScope); transaction.TransactionDisposing += OnTransactionDisposing; transaction.EnlistScope(scope); _transactions.AddFirst(transaction); return; } CurrentTransaction.EnlistScope(scope); }
/// <summary> /// Enlists a <see cref="UnitOfWorkScope"/> instance with the transaction manager, /// with the specified transaction mode. /// </summary> /// <param name="scope">The <see cref="IUnitOfWorkScope"/> to register.</param> /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transaciton /// mode of the unit of work.</param> public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { _logger.Info(string.Format("Enlisting scope {0} with transaction manager {1} with transaction mode {2}", scope.ScopeId, _transactionManagerId, mode)); var uowFactory = ServiceLocator.Current.GetInstance<IUnitOfWorkFactory>(); if (_transactions.Count == 0 || mode == TransactionMode.New || mode == TransactionMode.Supress) { _logger.Debug(string.Format("Enlisting scope {0} with mode {1} requires a new TransactionScope to be created.", scope.ScopeId, mode)); var txScope = TransactionScopeHelper.CreateScope(UnitOfWorkSettings.DefaultIsolation, mode); var unitOfWork = uowFactory.Create(); var transaction = new UnitOfWorkTransaction(unitOfWork, txScope); transaction.TransactionDisposing += OnTransactionDisposing; transaction.EnlistScope(scope); _transactions.AddFirst(transaction); return; } CurrentTransaction.EnlistScope(scope); }
private void ProcessWorkItem(IUnitOfWorkScope scope, IAggregateRegistration registration, IDomainNotificationBus bus, IReadModelWorkItem workItem) { var eventScope = this.context.BeginUnitOfWork(); using (eventScope) { var events = eventScope.GetRegisteredObject <IEventStore>().GetEventsAfterVersion(workItem.Identity, workItem.FromVersion - 1).ToList(); var builders = registration.DelayedReadModels(scope); foreach (var builder in builders) { if (workItem.FromVersion == 0) { builder.DeleteForAggregate(workItem.Identity); } // we need to get the events from the event store var builderEvents = builder.Process(events); foreach (var evt in builderEvents) { bus.Publish(evt); } } } }
/// <summary> /// Enlists a <see cref="UnitOfWorkScope"/> instance with the transaction manager, /// with the specified transaction mode. /// </summary> /// <param name="scope">The <see cref="IUnitOfWorkScope"/> to register.</param> /// <param name="mode">A <see cref="TransactionMode"/> enum specifying the transaciton /// mode of the unit of work.</param> public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { _logger.Info(x => x("Enlisting scope {0} with transaction manager {1} with transaction mode {2}", scope.ScopeId, _transactionManagerId, mode)); var uowFactory = ServiceLocator.Current.GetInstance <IUnitOfWorkFactory>(); if (_transactions.Count == 0 || mode == TransactionMode.New || mode == TransactionMode.Supress) { _logger.Debug(x => x("Enlisting scope {0} with mode {1} requires a new TransactionScope to be created.", scope.ScopeId, mode)); var txScope = TransactionScopeHelper.CreateScope(UnitOfWorkSettings.DefaultIsolation, mode); var unitOfWork = uowFactory.Create(); var transaction = new UnitOfWorkTransaction(unitOfWork, txScope); transaction.TransactionDisposing += OnTransactionDisposing; transaction.EnlistScope(scope); _transactions.AddFirst(transaction); return; } CurrentTransaction.EnlistScope(scope); }
public ScrapApplicationService( IScrapFactory scrapFactory, IScrapRepository scrapRepository, IUnitOfWorkScope unitOfWorkScope, IScrapDomainService scrapDomainService, IVesselInCompanyDomainService vesselDomianService, ICompanyDomainService companyDomainService, ICurrencyDomainService currencyDomainService, IGoodDomainService goodDomainService, IGoodUnitDomainService goodUnitDomainService, ITankDomainService tankDomainService) { this.scrapFactory = scrapFactory; this.scrapRepository = scrapRepository; this.unitOfWorkScope = unitOfWorkScope; this.scrapDomainService = scrapDomainService; this.vesselDomianService = vesselDomianService; this.companyDomainService = companyDomainService; this.currencyDomainService = currencyDomainService; this.goodDomainService = goodDomainService; this.goodUnitDomainService = goodUnitDomainService; this.tankDomainService = tankDomainService; }
/// <summary> /// Callback executed when an enlisted scope has comitted. /// </summary> void OnScopeCommitting(IUnitOfWorkScope scope) { _logger.Info(x => x("Commit signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); if (!_attachedScopes.Contains(scope)) { Dispose(); throw new InvalidOperationException("The scope being comitted is not attached to the current transaction."); } scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); if (_attachedScopes.Count == 0) { _logger.Info(x => x("All scopes have signalled a commit on transaction {0}. Flushing unit of work and comitting attached TransactionScope.", _transactionId)); try { _unitOfWork.Flush(); _transaction.Complete(); } finally { Dispose(); //Dispose the transaction after comitting. } } }
public ClaimRpository(IUnitOfWorkScope unitOfWorkScope) : base(unitOfWorkScope) { init(); }
public void EnlistScope(IUnitOfWorkScope scope, TransactionMode mode) { scope.ScopeComitting += OnScopeCommitting; scope.ScopeRollingback += OnScopeRollingback; }
/// <summary> /// Attaches a <see cref="UnitOfWorkScope"/> instance to the /// <see cref="UnitOfWorkTransaction"/> instance. /// </summary> /// <param name="scope">The <see cref="UnitOfWorkScope"/> instance to attach.</param> public void EnlistScope(IUnitOfWorkScope scope) { Check.Assert<ArgumentNullException>(scope != null, "Expected a non-null IUnitOfWorkScope instance."); Logger.Log(LogLevel.Debug,string.Format("Scope {1} enlisted with transaction {1}", scope.ScopeId, _transactionId)); _attachedScopes.Add(scope); scope.ScopeComitting += OnScopeCommitting; scope.ScopeRollingback += OnScopeRollingBack; }
/// <summary> /// Callback executed when an enlisted scope has comitted. /// </summary> void OnScopeCommitting(IUnitOfWorkScope scope) { Check.Assert<ObjectDisposedException>(!_disposed, "The transaction attached to the scope has already been disposed."); Logger.Log(LogLevel.Debug, string.Format("Commit signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); if (!_attachedScopes.Contains(scope)) { Dispose(); throw new InvalidOperationException("The scope being comitted is not attached to the current transaction."); } scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); if (_attachedScopes.Count == 0) { Logger.Log(LogLevel.Debug, string.Format("All scopes have signalled a commit on transaction {0}. Flushing unit of work and comitting attached TransactionScope.", _transactionId)); try { _unitOfWork.Flush(); _transaction.Complete(); } finally { Dispose(); //Dispose the transaction after comitting. } } }
private void ProcessWorkItem(IUnitOfWorkScope scope, IAggregateRegistration registration, IDomainNotificationBus bus, IReadModelWorkItem workItem) { var eventScope = this.context.BeginUnitOfWork(); using (eventScope) { var events = eventScope.GetRegisteredObject<IEventStore>().GetEventsAfterVersion(workItem.Identity, workItem.FromVersion - 1).ToList(); var builders = registration.DelayedReadModels(scope); foreach (var builder in builders) { if (workItem.FromVersion == 0) { builder.DeleteForAggregate(workItem.Identity); } // we need to get the events from the event store var builderEvents = builder.Process(events); foreach (var evt in builderEvents) { bus.Publish(evt); } } } }
/// <summary> /// Callback executed when an enlisted scope is rolledback. /// </summary> void OnScopeRollingBack(IUnitOfWorkScope scope) { _logger.Info(x => x("Rollback signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); _logger.Info(x => x("Detaching all scopes and disposing of attached TransactionScope on transaction {0}", _transactionId)); scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); Dispose(); }
/// <summary> /// Attaches a <see cref="UnitOfWorkScope"/> instance to the /// <see cref="UnitOfWorkTransaction"/> instance. /// </summary> /// <param name="scope">The <see cref="UnitOfWorkScope"/> instance to attach.</param> public void EnlistScope(IUnitOfWorkScope scope) { _logger.Info(x => x("Scope {1} enlisted with transaction {1}", scope.ScopeId, _transactionId)); _attachedScopes.Add(scope); scope.ScopeComitting += OnScopeCommitting; scope.ScopeRollingback += OnScopeRollingBack; }
/// <summary> /// Callback executed when an enlisted scope is rolledback. /// </summary> void OnScopeRollingBack(IUnitOfWorkScope scope) { Check.Assert<ObjectDisposedException>(!_disposed, "The transaction attached to the scope has already been disposed."); Logger.Log(LogLevel.Debug, string.Format("Rollback signalled by scope {0} on transaction {1}.", scope.ScopeId, _transactionId)); Logger.Log(LogLevel.Debug, string.Format("Detaching all scopes and disposing of attached TransactionScope on transaction {0}", _transactionId)); scope.ScopeComitting -= OnScopeCommitting; scope.ScopeRollingback -= OnScopeRollingBack; scope.Complete(); _attachedScopes.Remove(scope); Dispose(); }
public InquiryJobIndexPointRepository(IUnitOfWorkScope unitOfWorkScope) : base(unitOfWorkScope) { init(); }
public ReadModelBuilderQueue(IUnitOfWorkScope scope) { var connection = scope.GetRegisteredObject<SQLiteConnection>(); this.repository = new SqlRepository<ReadModelWorkItem>(connection); this.repository.Connection.CreateTable<ReadModelWorkItem>(); }
public CharterOutRepository(IUnitOfWorkScope unitOfWorkScope) : base(unitOfWorkScope) { }
public void Begin() { _scope = _unitOfWork.CreateTransactionalScope(UnitOfWorkTransactionOptions.Default()); }
public VoyageApplicationService(IVoyageRepository repository,IUnitOfWorkScope uows) { _repository = repository; }
void OnScopeRollingback(IUnitOfWorkScope scope) { IncrementRollback(scope.ScopeId); if (ScopeRollbackAction != null) ScopeRollbackAction(scope); scope.ScopeRollingback -= OnScopeRollingback; }