コード例 #1
0
ファイル: Startup.cs プロジェクト: ivanbarros/TesteBeltis
 // This method gets called by the runtime. Use this method to add services to the container.
 public void ConfigureServices(IServiceCollection services)
 {
     services.AddControllersWithViews();
     MigratorServices.CreateService(Configuration["sqlDb:connectionString"]);
     ConfigureService.ConfigureDependenciesService(services);
     ConfigureRepository.ConfigureDependenciesRepositories(services);
     services.AddSqlDatabase(Configuration);
     services.AddMemoryCache();
 }
コード例 #2
0
        // This method gets called by the runtime. Use this method to add services to the container.

        public void ConfigureServices(IServiceCollection services)
        {
            MigratorServices.CreateService(Configuration["mysqlDb:connectionString"]);
            ConfigureService.ConfigureDependenciesService(services);
            ConfigureRepository.ConfigureDependenciesRepositories(services);

            services.AddMvc(opt => opt.Filters.Add <NotificationFilter>())
            .SetCompatibilityVersion(CompatibilityVersion.Version_3_0);

            services.AddMySqlDatabase(Configuration);
            services.AddNotificationPattern();

            var signingConfigurations = new SigningConfigurations();

            services.AddSingleton(signingConfigurations);

            var tokenConfiguration = new TokenConfigurations();

            new ConfigureFromConfigurationOptions <TokenConfigurations>(
                Configuration.GetSection("TokenConfigurations")).Configure(tokenConfiguration);
            services.AddSingleton(tokenConfiguration);
            services.AddSwaggerFramework(environment, Configuration);

            services.AddAuthentication(authOptions =>
            {
                authOptions.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
                authOptions.DefaultChallengeScheme    = JwtBearerDefaults.AuthenticationScheme;
            }).AddJwtBearer(bearerOptions =>
            {
                var paramsValidation = bearerOptions.TokenValidationParameters;
                paramsValidation.IssuerSigningKey         = signingConfigurations.SecurityKey;
                paramsValidation.ValidAudience            = tokenConfiguration.Audience;
                paramsValidation.ValidIssuer              = tokenConfiguration.Issuer;
                paramsValidation.ValidateIssuerSigningKey = true;
                paramsValidation.ClockSkew = TimeSpan.Zero;
            });
            services.AddAuthorization(auth =>
            {
                auth.AddPolicy("Bearer", new AuthorizationPolicyBuilder()
                               .AddAuthenticationSchemes(JwtBearerDefaults.AuthenticationScheme)
                               .RequireAuthenticatedUser().Build());
            });
        }