Ejemplo n.º 1
0
 public void ConfigureServices(IServiceCollection services)
 {
     SimpleInjectorConfiguration.ConfigureServices(services, _configuration);
     CorsConfiguration.ConfigureServices(services);
     MvcConfiguration.ConfigureServices(services);
     SwaggerConfiguration.ConfigureServices(services);
     HangfireConfiguration.ConfigureServices(services, _configuration);
     DatabaseConfiguration.ConfigureServices(services, _configuration);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Configures the services added to the container.
        /// </summary>
        /// <remarks>This method is called by asp.net core runtime.</remarks>
        /// <param name="services">The service collection.</param>
        public void ConfigureServices(IServiceCollection services)
        {
            CorsConfiguration.ConfigureServices(services);

            services.AddLocalization(options => options.ResourcesPath = "Resources");
            services.AddMvc()
            .AddViewLocalization(options => options.ResourcesPath = "Resources")
            .AddDataAnnotationsLocalization();

            services.AddControllers();

            // Configure strongly typed settings objects
            var appSettingsSection = this.Configuration.GetSection("AppSettings");

            services.Configure <AppSettings>(appSettingsSection);

            // Configure jwt authentication
            var appSettings = appSettingsSection.Get <AppSettings>();
            var key         = Encoding.ASCII.GetBytes(appSettings.Security.JWT.Secret);

            services.AddAuthentication(x =>
            {
                x.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                x.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            })
            .AddJwtBearer(x =>
            {
                x.RequireHttpsMetadata      = false;
                x.SaveToken                 = true;
                x.TokenValidationParameters = new TokenValidationParameters
                {
                    ValidateIssuerSigningKey = true,
                    IssuerSigningKey         = new SymmetricSecurityKey(key),
                    ValidateIssuer           = false,
                    ValidateAudience         = false,
                };
            });

            // Configure DI for application services
            services.AddScoped <IUserService, UserService>();
            services.AddScoped <IUserPasswordResetTokenService, UserPasswordResetTokenService>();
            services.AddScoped <IEmailService, EmailService>();
            services.AddScoped <IEmailTemplateService, EmailTemplateService>();
            services.AddScoped <ISpeechToTextService, SpeechToTextService>();
            services.AddScoped <IGroceryActionService, GroceryActionService>();
            services.AddScoped <IGroceryItemService, GroceryItemService>();
            services.AddScoped <IGroceryQuantityService, GroceryQuantityService>();
            services.AddScoped <IGroceryMeaninglessWordService, GroceryMeaninglessWordService>();
        }