Пример #1
0
 public DummyService(
     IUnitOfWorkBase unitOfWork,
     IProductRepository productRepository)
 {
     _unitOfWork        = unitOfWork;
     _productRepository = productRepository;
 }
        /// <summary>
        /// Adds the given unit of work.
        /// (An error is thrown if the unit of work is already registered)
        /// </summary>
        /// <param name="reg">The unit of work registration.</param>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="reg"/> is null.</exception>
        /// <exception cref="ArgumentException">Thrown if the given unit of work is already registered.</exception>
        public void Add(IUnitOfWorkBase reg)
        {
            Throw.IfArgumentIsNull(reg, nameof(reg));

            if (!UowsById.TryAdd(reg.UowId, reg))
            {
                throw new ArgumentException($"Unit of work with Id {reg.UowId} already exists!", nameof(reg));
            }
        }
Пример #3
0
        public PaymentStatusService(IUnitOfWorkBase <PaymentContext> unitOfWork, ILogger <PaymentStatusService> logger)
        {
            UnitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));

            if (PaymentStatusRepo == null)
            {
                PaymentStatusRepo = UnitOfWork.GetRepository <PaymentStatus>();
            }

            Logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
Пример #4
0
 public void Register(IUnitOfWorkBase unitOfWork)
 {
     if (unitOfWork == null)
     {
         throw new ArgumentNullException(nameof(unitOfWork));
     }
     if (_unitOfWorks.Contains(unitOfWork) == false)
     {
         _unitOfWorks.Add(unitOfWork);
     }
 }
        /// <summary>
        /// Gets the unit of work with the given Id.
        /// </summary>
        /// <param name="uowId">Identifier of the unit of work.</param>
        /// <param name="throwIfNull">If set to <c>true</c> a <see cref="NullReferenceException"/> is thrown if the unit of work is not found; otherwise null is returned.</param>
        /// <returns>Returns the unit of work or null.</returns>
        /// <exception cref="NullReferenceException">Thrown if a unit of work with the given Id is not found and <paramref name="throwIfNull"/> is true.</exception>
        public IUnitOfWorkBase Get(int uowId, bool throwIfNull)
        {
            IUnitOfWorkBase ret = null;

            TryGet(uowId, out ret);
            if (throwIfNull && (ret == null))
            {
                throw new NullReferenceException(string.Format(System.Globalization.CultureInfo.InvariantCulture
                                                               , "Unit of work registration (Id = {0}) not found!", uowId));
            }
            return(ret);
        }
Пример #6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EntityReferenceByPk{TPrimaryKey, TEntity}"/> class.
        /// </summary>
        /// <param name="pk">The primary key value</param>
        /// <param name="uow">The UnitOfWork</param>
        public EntityReferenceByPk(TPrimaryKey pk, IUnitOfWorkBase uow)
        {
            Throw.IfArgumentIsNull(uow, nameof(uow));

            this.Pk      = pk;
            this._uowRef = new WeakReference <IUnitOfWorkBase>(uow, false);
            this._dbCtx  = uow.DbContext;
            if (CheckPkEqualityDelegate == null)
            {
                CheckPkEqualityDelegate = ((ModelEntityRegistration <TPrimaryKey, TEntity>) this._dbCtx.ModelEntityRegistrationsByType.Get <TEntity>(true)).CheckPkEqualityDelegate;
            }
        }
Пример #7
0
        public EntityRepoBase(IUnitOfWorkBase uow, Func <TEntity, TPrimaryKey> getEntityPkDelegate, Func <TPrimaryKey, TEntity> newEntityWithPkFactory, Func <TPrimaryKey, TPrimaryKey, bool> checkPkEqualityDelegate, Func <TPrimaryKey> newPkFactory = null)
        {
            Throw.IfArgumentIsNull(uow, nameof(uow));
            Throw.IfArgumentIsNull(getEntityPkDelegate, nameof(getEntityPkDelegate));
            Throw.IfArgumentIsNull(newEntityWithPkFactory, nameof(newEntityWithPkFactory));
            Throw.IfArgumentIsNull(checkPkEqualityDelegate, nameof(checkPkEqualityDelegate));

            this.Uow                     = uow;
            this._getEntityPk            = getEntityPkDelegate;
            this._newEntityWithPkFactory = newEntityWithPkFactory;
            this._checkPkEquality        = checkPkEqualityDelegate;
            this._newPkFactory           = newPkFactory;
            this.SupportsGenerateNewPk   = (newPkFactory != null);
        }
Пример #8
0
        private void RegisterUnitOfWork(IUnitOfWorkBase uow)
        {
            if (uow == null)
            {
                throw new ArgumentNullException(nameof(uow));
            }

            Logger?.LogTrace("Registering UnitOfWork ({uow.id}, {uow.type}) in {dbCtx.type}...", uow.UowId, uow.GetType(), this.GetType());

            ThrowIfDisposingOrDisposed();

            this.UowsById.Add(uow);

            OnUnitOfWorkAdded(uow);
            this.IsBusy = !this.UowsById.IsEmpty;
        }
        /// <summary>
        /// Gets the repo of the provided entity type, or if <paramref name="throwIfNull"/> is true then it throws <see cref="EntityRepoNotFoundException"/>, otherwise (if it's false) returns null
        /// </summary>
        /// <typeparam name="TEntity">The type of the entity</typeparam>
        /// <param name="uow">The unit of work</param>
        /// <param name="throwIfNull">True to throw <see cref="EntityRepoNotFoundException"/>, false to return null if the repo of the provided entity type not found</param>
        /// <exception cref="EntityRepoNotFoundException">Thrown when <paramref name="throwIfNull"/> is true and the repo of the entity type not found</exception>
        /// <returns>The repo of the provided entity type or null</returns>
        public static IEntityRepo <TEntity> GetRepo <TEntity>(this IUnitOfWorkBase uow, bool throwIfNull)
        {
            if (uow == null)
            {
                throw new ArgumentNullException("uow");
            }

            IEntityRepo <TEntity> repo;

            uow.TryGetRepo <TEntity>(out repo);
            if (throwIfNull && (repo == null))
            {
                throw EntityRepoNotFoundException.New <TEntity>();
            }
            return(repo);
        }
Пример #10
0
        public PaymentService(IPaymentStatusService paymentStatusService, IUnitOfWorkBase <PaymentContext> unitOfWork, ILogger <PaymentService> logger,
                              IExpensivePaymentGateway expensivePaymentGateway, ICheapPaymentGateway cheapPaymentGateway, IPremiumPaymentService premiumPaymentService)
        {
            PaymentStatusService = paymentStatusService;

            UnitOfWork = unitOfWork ?? throw new ArgumentNullException(nameof(unitOfWork));

            if (PaymentRepo == null)
            {
                PaymentRepo = UnitOfWork.GetRepository <Payment>();
            }

            ExpensivePaymentGateway = expensivePaymentGateway;
            CheapPaymentGateway     = cheapPaymentGateway;
            PremiumPaymentService   = premiumPaymentService;

            Logger = logger ?? throw new ArgumentNullException(nameof(logger));
        }
Пример #11
0
        /// <summary>
        /// Unregisters the provided UnitOfWork instance
        /// </summary>
        /// <param name="uow"></param>
        protected internal void UnregisterUnitOfWork(IUnitOfWorkBase uow)
        {
            if (uow == null)
            {
                throw new ArgumentNullException(nameof(uow));
            }

            Logger?.LogTrace("Unregistering UnitOfWork ({uow.id}, {uow.type}) in {dbCtx.type}...", uow.UowId, uow.GetType(), this.GetType());

            //ThrowIfDisposingOrDisposed();

            if (this.UowsById.TryRemove(uow.UowId, out var removedUow))
            {
                if (!object.ReferenceEquals(uow, removedUow))
                {
                    throw new ArgumentException($"Unit of work instance removed by Id {uow.UowId} not equals the given instance!");
                }

                Logger?.LogTrace("UnitOfWork ({uow.id}, {uow.type}) removed from {dbCtx.type}.", uow.UowId, uow.GetType(), this.GetType());

                OnUnitOfWorkRemoved(uow);
                this.IsBusy = !this.UowsById.IsEmpty;
            }
        }
Пример #12
0
 public QuerySingleHandlerBaseAsync(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
 }
Пример #13
0
 public QueryListHandlerBaseAsync(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
 }
 public CloudProviderService(IUnitOfWorkBase unitOfWorkBase)
 {
     _unitOfWorkBase = unitOfWorkBase;
 }
Пример #15
0
 public QuerySingleHandlerBase(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
     SingleResult = new QuerySingleResultBase <TResultType>();
 }
Пример #16
0
 public QueryAsyncHandlerBase(IUnitOfWorkBase unitOfWork)
 {
     UnitOfWork = unitOfWork;
 }
 public CommandHandlerBaseAsyncTask(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
 }
Пример #18
0
 public QueryCollectionAsyncHandlerBase(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
 }
Пример #19
0
 public CommandHandlerBase(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
 }
Пример #20
0
 /// <summary>
 /// Method that is called after a UnitOfWork is added
 /// </summary>
 /// <param name="uow">The added UnitOfWork instance</param>
 protected virtual void OnUnitOfWorkAdded(IUnitOfWorkBase uow)
 {
 }
Пример #21
0
 public CommandAsyncHandlerBase(IUnitOfWorkBase unitOfWork)
 {
     UnitOfWork   = unitOfWork;
     SericeResult = new CommandResultBase <TResultType>();
     Context      = new RequestContext();
 }
        /// <summary>
        /// Gets the repo of the provided entity type with the provided primary key type, or if <paramref name="throwIfNull"/> is true then it throws <see cref="EntityWithPkRepoNotFoundException"/>, otherwise (if it's false) returns null
        /// </summary>
        /// <typeparam name="TPrimaryKey">The type of the primary key</typeparam>
        /// <typeparam name="TEntity">The type of the entity</typeparam>
        /// <param name="uow"></param>
        /// <param name="throwIfNull">True to throw <see cref="EntityWithPkRepoNotFoundException"/>, false to return null if the repo of the provided entity type with the provided primary key type not found</param>
        /// <exception cref="EntityWithPkRepoNotFoundException">Thrown when <paramref name="throwIfNull"/> is true and the repo of the entity with the provided primary key type not found</exception>
        /// <returns>The repo of the provided entity type with the provided primary key type or null</returns>
        public static IEntityRepo <TPrimaryKey, TEntity> GetRepo <TPrimaryKey, TEntity>(this IUnitOfWorkBase uow, bool throwIfNull)
            where TEntity : IReadOnlyPkHolder <TPrimaryKey>
        {
            if (uow == null)
            {
                throw new ArgumentNullException("uow");
            }

            IEntityRepo <TPrimaryKey, TEntity> repo;

            uow.TryGetRepo <TPrimaryKey, TEntity>(out repo);
            if (throwIfNull && (repo == null))
            {
                throw EntityWithPkRepoNotFoundException.New <TPrimaryKey, TEntity>();
            }
            return(repo);
        }
Пример #23
0
 public CommandDeleteHandlerBase(IUnitOfWorkBase unitOfWork, IMapper mapper)
     : base(unitOfWork)
 {
     Mapper = mapper;
 }
 /// <summary>
 /// Tries to get the unit of work with the given Id.
 /// </summary>
 /// <param name="uowId">Identifier of the unit of work.</param>
 /// <param name="reg">The unit of work registered with the given Id.</param>
 /// <returns>Returns true if the unit of work for the given Id is found; otherwise false.</returns>
 public bool TryGet(int uowId, out IUnitOfWorkBase reg)
 {
     return(UowsById.TryGetValue(uowId, out reg) && (reg != null));
 }
Пример #25
0
 public HandlerBase(IUnitOfWorkBase unitOfWork)
 {
     UnitOfWork = unitOfWork;
 }
 /// <summary>
 /// Tries to remove the unit of work with the given identifier.
 /// </summary>
 /// <param name="uowId">Identifier of the unit of work.</param>
 /// <param name="removedInstance">The removed unit of work instance.</param>
 /// <returns>
 ///   <c>true</c> if a unit of work with the given identifier is successfully found and removed; otherwise, <c>false</c>.
 /// </returns>
 public bool TryRemove(int uowId, out IUnitOfWorkBase removedInstance)
 {
     return(UowsById.TryRemove(uowId, out removedInstance));
 }
Пример #27
0
 public QueryListAsyncHandlerBase(IUnitOfWorkBase unitOfWork)
     : base(unitOfWork)
 {
     CollectionResult = new QueryListResultBase <TResultType>();
 }
Пример #28
0
 public CommandUpdateHandlerBaseAsync(IUnitOfWorkBase unitOfWork, IMapper mapper)
     : base(unitOfWork)
 {
     Mapper = mapper;
 }
 public CommandHandlerBaseAsyncVoid(IUnitOfWorkBase unitOfWork)
 {
     UnitOfWork = unitOfWork;
 }
Пример #30
0
 /// <summary>
 /// Method that is called after a UnitOfWork is removed
 /// </summary>
 /// <param name="uow">The removed UnitOfWork instance</param>
 protected virtual void OnUnitOfWorkRemoved(IUnitOfWorkBase uow)
 {
 }