示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);

            DependencyInjectionBootstraper.InitializeAppSettings(services, this.Configuration);
            DependencyInjectionBootstraper.RegisterServices(services, this.Configuration);
        }
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(
            IServiceCollection services)
        {
            services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
            .AddJsonOptions(options =>
            {
                options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
                options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
            });

            var identitySettings = new IdentitySettings();

            Configuration.GetSection(SectionNames.ApplicationIdentitySection).Bind(identitySettings);

            //services.AddAuthentication(options =>
            //{
            //    options.DefaultAuthenticateScheme = JwtBearerDefaults.AuthenticationScheme;
            //    options.DefaultChallengeScheme = JwtBearerDefaults.AuthenticationScheme;
            //}).AddIdentityServerAuthentication(options =>
            //{
            //    options.Authority = identitySettings.Authority;
            //    options.RequireHttpsMetadata = false;
            //    options.ApiName = identitySettings.ApiName;
            //    options.ApiSecret = identitySettings.ClientSecret;
            //    options.ClaimsIssuer = identitySettings.Authority;

            //});


            services
            .AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme)
            .AddCookie();

            services.AddSwagger(identitySettings);

            services.AddDataProtection();

            // Adding MediatR for Domain Events and Notifications
            services.AddMediatR(typeof(Startup));

            services.AddHttpClient("BankService", config =>
            {
                config.BaseAddress = new Uri(Configuration["Services:Bank"]);
            }).AddTransientHttpErrorPolicy(p => p.WaitAndRetryAsync(5, _ => TimeSpan.FromMinutes(5)));

            DependencyInjectionBootstraper.InitializeAppSettings(services, this.Configuration);
            DependencyInjectionBootstraper.RegisterServices(services, this.Configuration);
        }