Beispiel #1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddHttpContextAccessor();
            services.AddCodeFirstGrpc();
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Identity.API",
                    Version = "v1"
                });
            });

            services.Configure <JwtConfig>(Configuration.GetSection("JwtConfig"));
            services.AddJwtAuthentication();
            services.AddMediatR(typeof(Startup).Assembly);

            var sqlServerConnectionString = services.GetSqlServerConnectionString();

            services.AddDbContext <AppDbContext>(builder =>
                                                 builder
                                                 .UseSqlServer(sqlServerConnectionString)
                                                 .UseLazyLoadingProxies()
                                                 .UseLoggerFactory(LoggerFactory.Create(loggingBuilder => loggingBuilder.AddDebug()))
                                                 );

            var redisConnectionString = Configuration.GetRedisConnectionString();

            services.AddDistributedRedisCache(options => options.Configuration = redisConnectionString);

            services.AddHealthChecks()
            .AddSqlServer(sqlServerConnectionString)
            .AddRedis(redisConnectionString);

            AssemblyScanner.FindValidatorsInAssembly(typeof(Startup).Assembly)
            .ForEach(item => services.AddScoped(item.InterfaceType, item.ValidatorType));
            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>));

            services.AddExceptionHandling <IdentityDomainException>();

            services.AddSingleton <PasswordValidatorBase, PasswordValidator>();
            services.AddSingleton <IPasswordHasher, PasswordHasher>();

            services.AddScoped <IUserRepository, UserRepository>();
            services.AddScoped <IRefreshTokenRepository, RefreshTokenRepository>();

            services.AddSingleton <IAccessTokenService, AccessTokenService>();
            services.AddScoped <IRefreshTokenService, RefreshTokenService>();

            services.AddSingleton <IAccessTokenDecoder, AccessTokenDecoder>();
            services.AddSingleton <IRefreshTokenDecoder, RefreshTokenDecoder>();

            services.AddScoped <ISellerInfoRepository, SellerInfoRepository>();

            if (!EnvironmentHelpers.IsSeedingDatabase())
            {
                services.AddEventBus();
            }
        }
Beispiel #2
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddHttpContextAccessor();
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Carts.API",
                    Version = "v1"
                });
            });

            services.ReadServicesEndpoints();

            services.AddJwtAuthentication();
            services.AddMediatR(typeof(Startup).Assembly);

            var connectionString = services.GetSqlServerConnectionString();

            services.AddDbContext <AppDbContext>(builder =>
                                                 builder
                                                 .UseSqlServer(connectionString)
                                                 .UseLazyLoadingProxies()
                                                 .UseLoggerFactory(LoggerFactory.Create(loggingBuilder => loggingBuilder.AddDebug()))
                                                 );
            services.AddHealthChecks()
            .AddSqlServer(connectionString);

            AssemblyScanner.FindValidatorsInAssembly(typeof(Startup).Assembly)
            .ForEach(item => services.AddScoped(item.InterfaceType, item.ValidatorType));
            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>));

            services.AddScoped <ICartRepository, CartRepository>();
            services.AddScoped <ICartItemRepository, CartItemRepository>();

            services.AddScoped <IGrpcServiceClientFactory <IOffersService>, GrpcServiceClientFactory <IOffersService> >();
            services.AddScoped <IGrpcServiceClientFactory <IOrdersService>, GrpcServiceClientFactory <IOrdersService> >();

            services.AddExceptionHandling <CartsDomainException>();

            if (!EnvironmentHelpers.IsSeedingDatabase())
            {
                services.AddEventBus();
            }
        }
Beispiel #3
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers();
            services.AddJwtAuthentication();
            services.AddHttpContextAccessor();
            services.ConfigureSignalR();

            services.Configure <NotificationSettings>(Configuration.GetSection("NotificationSettings"));

            services.AddMediatR(typeof(Startup).Assembly);

            var connectionString = services.GetSqlServerConnectionString();

            services.AddDbContext <AppDbContext>(builder =>
            {
                builder
                .UseSqlServer(connectionString)
                .UseLoggerFactory(LoggerFactory.Create(loggingBuilder => loggingBuilder.AddDebug()));
            },
                                                 contextLifetime: ServiceLifetime.Scoped,
                                                 optionsLifetime: ServiceLifetime.Scoped
                                                 );
            services.ConfigureHealthchecks();

            var notificationOptions = Configuration.GetSection("NotificationSettings").Get <NotificationSettings>();

            services.AddScheduler(builder =>
            {
                builder.AddJob <CleanupJob>(configure: options =>
                {
                    options.CronSchedule = notificationOptions.CleanupJobCronPattern;
                });
            });

            services.AddSingleton <IConnectionManager, ConnectionManager>();
            services.AddSingleton <INotificationCache, NotificationCache>();
            services.AddTransient <INotificationRepository, NotificationRepository>();

            if (!EnvironmentHelpers.IsSeedingDatabase())
            {
                services.Configure <AzureEventBusConfig>(Configuration.GetSection("EventBus:AzureEventBus"));
                services.AddEventBus();
            }
        }
Beispiel #4
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddRequestLocalization(options =>
            {
                options.DefaultRequestCulture = new RequestCulture(CultureInfo.InvariantCulture);
            });

            services.AddControllers();
            services.AddHttpContextAccessor();
            services.AddCodeFirstGrpc();
            services.AddSwaggerGen(options =>
            {
                options.SwaggerDoc("v1", new OpenApiInfo
                {
                    Title   = "Offers.API",
                    Version = "v1"
                });
            });

            services.ReadServicesEndpoints();
            services.AddJwtAuthentication();
            services.AddMediatR(typeof(Startup).Assembly);

            services.AddBlobStorage();
            services.AddSingleton <IImageStorage, ImageStorage>();

            var connectionString = services.GetSqlServerConnectionString();

            services.AddDbContext <AppDbContext>(builder =>
                                                 builder
                                                 .UseSqlServer(connectionString)
                                                 .UseLazyLoadingProxies()
                                                 .UseLoggerFactory(LoggerFactory.Create(loggingBuilder => loggingBuilder.AddDebug()))
                                                 );
            services.AddHealthChecks()
            .AddSqlServer(connectionString);

            AssemblyScanner.FindValidatorsInAssembly(typeof(Startup).Assembly)
            .ForEach(item => services.AddScoped(item.InterfaceType, item.ValidatorType));
            services.AddScoped(typeof(IPipelineBehavior <,>), typeof(ValidationBehavior <,>));

            services.AddScoped <IRequestOfferImagesProcessor, RequestOfferImagesProcessor>();
            services.AddScoped <IRequestOfferImagesMetadataExtractor, RequestOfferImagesMetadataExtractor>();
            services.AddScoped <IRequestDeliveryMethodExtractor, RequestDeliveryMethodExtractor>();
            services.AddScoped <IRequestKeyValueInfoExtractor, RequestKeyValueInfoExtractor>();

            services.AddScoped <IOfferRepository, OfferRepository>();
            services.AddScoped <ICategoryRepository, CategoryRepository>();
            services.AddScoped <IPredefinedDeliveryMethodRepository, PredefinedDeliveryMethodRepository>();

            services.AddEventDispatching <DomainEventReducer>();
            services.AddScoped <IOfferDomainEventReducer, OfferDomainEventReducer>();

            services.AddExceptionHandling <OffersDomainException>();

            services.AddScoped <IGrpcServiceClientFactory <IOrdersService>, GrpcServiceClientFactory <IOrdersService> >();

            if (!EnvironmentHelpers.IsSeedingDatabase())
            {
                services.AddEventBus();
            }
        }