コード例 #1
0
        public static void RegisterServices(IServiceCollection services)
        {
            var mappingConfig = new MapperConfiguration(mc =>
            {
                mc.AddProfile(new ServicesMapperProfile());
            });

            IMapper mapper = mappingConfig.CreateMapper();

            services.AddSingleton(mapper);

            RepositoriesInjector.RegisterServices(services);
            ServicesInjector.RegisterServices(services);

            var key = Encoding.ASCII.GetBytes(SecuritySettings.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
                };
            });
        }
コード例 #2
0
        private void ConfigureInjection(IServiceCollection services)
        {
            services.AddSingleton(ConfigureMapper());

            services.AddScoped <IDbConnection>(_ => GetConnection());
            AcceInjector.Config(services);
            ServicesInjector.Config(services);
            RepositoriesInjector.Config(services);
        }