예제 #1
0
        public ShopManager(
            IShopRepository repository,
            ILogger <ShopManager> logger,
            IHttpContextAccessor context,
            IOptions <ShopManagerOptions> optionsAccessor,
            IEnumerable <IShopValidator <Product> > prodValidators,
            IEnumerable <IShopValidator <Image> > imgValidators,
            IEnumerable <IShopValidator <Category> > catValidators,
            IEnumerable <IShopValidator <DescriptionGroup> > descGroupValidators,
            IEnumerable <IShopValidator <DescriptionGroupItem> > descGroupItemValidators,
            IEnumerable <IShopValidator <Description> > descValidators,
            IEnumerable <IShopValidator <Order> > orderValidators,
            IShopImageTransformer <Image> imgTransformer,
            OperationErrorDescriber errorDescriber = null)
        {
            _repository       = repository ?? throw new ArgumentNullException(nameof(repository));
            _logger           = logger ?? throw new ArgumentNullException(nameof(logger));
            ErrorDescriber    = errorDescriber ?? new OperationErrorDescriber();
            Options           = optionsAccessor.Value ?? new ShopManagerOptions();
            CancellationToken = context?.HttpContext?.RequestAborted ?? CancellationToken.None;

            //TODO create single validator class
            foreach (var validator in prodValidators)
            {
                ProductValidators.Add(validator);
            }

            foreach (var validator in imgValidators)
            {
                ImageValidators.Add(validator);
            }

            foreach (var validator in catValidators)
            {
                CategoryValidators.Add(validator);
            }

            foreach (var validator in descGroupValidators)
            {
                DescriptionGroupValidators.Add(validator);
            }

            foreach (var validator in descGroupItemValidators)
            {
                DescriptionGroupItemValidators.Add(validator);
            }

            foreach (var validator in descValidators)
            {
                DescriptionValidators.Add(validator);
            }

            foreach (var validator in orderValidators)
            {
                OrderValidators.Add(validator);
            }

            ImageTransformer = imgTransformer ??
                               new ShopImageTransformer(optionsAccessor);
        }
예제 #2
0
 public ShopRepository(DbContext dbContext, IHostingEnvironment environment,
                       ILogger <ShopRepository> logger, OperationErrorDescriber describer = null)
 {
     ErrorDescriber      = describer ?? new OperationErrorDescriber();
     Context             = dbContext ?? throw new ArgumentNullException(nameof(dbContext));
     _hostingEnvironment = environment ?? throw new ArgumentNullException(nameof(environment));
     _logger             = logger ?? throw new ArgumentNullException(nameof(logger));
 }
예제 #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContactStore" /> class.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="errorDescriber">The <see cref="OperationErrorDescriber" />.</param>
        /// <exception cref="System.ArgumentNullException">context</exception>
        public ContactStore(DbContext context, OperationErrorDescriber errorDescriber = null)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            Context        = context;
            ErrorDescriber = errorDescriber ?? new OperationErrorDescriber();
        }
예제 #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ContactManager" /> class.
        /// </summary>
        /// <param name="store">The persistence store the manager will operate over.</param>
        /// <param name="errorDescriber">The <see cref="OperationErrorDescriber" /> used to provider error messages.</param>
        /// <param name="services">The <see cref="IServiceProvider" /> used to resolve services.</param>
        /// <exception cref="System.ArgumentNullException">store</exception>
        public ContactManager(IContactStore store, OperationErrorDescriber errorDescriber, IServiceProvider services = null)
        {
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (errorDescriber == null)
            {
                throw new ArgumentNullException(nameof(errorDescriber));
            }

            Store          = store;
            ErrorDescriber = errorDescriber;

            if (services != null)
            {
                _cancellationTokenAccessor = services.GetService(typeof(ICancellationTokenAccessor)) as ICancellationTokenAccessor;
            }
        }