// This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var executingAssembly = Assembly.GetExecutingAssembly();

            var databaseEngine = Configuration["AppSettings:DatabaseEngine"];

            DbConfiguration.SetConfiguration(new DatabaseEngineDbConfiguration(databaseEngine));

            services.AddDbContext <AdminAppDbContext>(ConfigureForAdminDatabase);
            services.AddDbContext <AdminAppIdentityDbContext>(ConfigureForAdminDatabase);
            services.AddDbContext <AdminAppDataProtectionKeysDbContext>(ConfigureForAdminDatabase);

            services.AddIdentity <AdminAppUser, IdentityRole>()
            .AddEntityFrameworkStores <AdminAppIdentityDbContext>()
            .AddDefaultTokenProviders();

            services.AddControllersWithViews(options =>
            {
                options.Filters.Add(new AuthorizeFilter("UserMustExistPolicy"));
                options.Filters.Add <AutoValidateAntiforgeryTokenAttribute>();
                options.Filters.Add <JsonValidationFilter>();
                options.Filters.Add <SetupRequiredFilter>();
                options.Filters.Add <UserContextFilter>();
                options.Filters.Add <PasswordChangeRequiredFilter>();
                options.Filters.Add <InstanceContextFilter>();
            })
            .AddFluentValidation(
                opt =>
            {
                opt.RegisterValidatorsFromAssembly(executingAssembly);

                opt.ValidatorOptions.DisplayNameResolver = (type, memberInfo, expression)
                                                           => memberInfo?
                                                           .GetCustomAttribute <System.ComponentModel.DataAnnotations.DisplayAttribute>()?.GetName();
            });

            services.AddWebOptimizer(
                pipeline =>
            {
                var minifyJsSettings = new CodeSettings
                {
                    LocalRenaming = LocalRenaming.CrunchAll,
                    MinifyCode    = true
                };

                var minifyCssSettings = new CssSettings
                {
                    MinifyExpressions = true
                };

                pipeline.AddCssBundle("/bundles/bootstrap-multiselect.min.css", minifyCssSettings, "/content/css/bootstrap-multiselect.css");
                pipeline.AddCssBundle("/bundles/site.min.css", minifyCssSettings, "/content/css/Site.css");
                pipeline.AddJavaScriptBundle("/bundles/bootstrap-multiselect.min.js", minifyJsSettings, "/Scripts/bootstrap-multiselect.js");
                pipeline.AddJavaScriptBundle("/bundles/modernizr.min.js", minifyJsSettings, "/Scripts/modernizr-2.8.3.js");
                pipeline.AddJavaScriptBundle("/bundles/site.min.js", minifyJsSettings, "/Scripts/site.js", "/Scripts/site-form-handlers.js", "/Scripts/signalr-progress.js");
                pipeline.AddJavaScriptBundle("/bundles/claimset.min.js", minifyJsSettings, "/Scripts/resource-editor.js");
                pipeline.AddJavaScriptBundle("/bundles/authstrategy.min.js", minifyJsSettings, "/Scripts/auth-editor.js");
            });

            services.AddAuthorization(options =>
            {
                options.AddPolicy("UserMustExistPolicy",
                                  policyBuilder =>
                {
                    policyBuilder.AddRequirements(new UserMustExistRequirement());
                });
            });

            services.AddScoped <IAuthorizationHandler, UserMustExistHandler>();

            services.Configure <IdentityOptions>(options =>
            {
                options.User.RequireUniqueEmail = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Identity/Login";
                options.LogoutPath       = "/Identity/LogOut";
                options.AccessDeniedPath = "/Identity/Login";
            });

            services.AddDataProtection().PersistKeysToDbContext <AdminAppDataProtectionKeysDbContext>();

            services.AddAutoMapper(executingAssembly, typeof(AdminManagementMappingProfile).Assembly);

            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            services.AddSignalR();

            services.AddHttpClient();

            var appSettings = new AppSettings();

            Configuration.GetSection("AppSettings").Bind(appSettings);
            ConfigurationAppSettings = appSettings;

            var connectionStrings = new ConnectionStrings();

            Configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            ConfigurationConnectionStrings = connectionStrings;

            var appStartup = appSettings.AppStartup;

            if (appStartup == "OnPrem")
            {
                new OnPremInstaller().Install(services, appSettings);
            }

            services.AddHangfire(configuration => configuration
                                 .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                                 .UseSimpleAssemblyNameTypeSerializer()
                                 .UseRecommendedSerializerSettings());
            HangFireInstance.EnableWithoutSchemaMigration();
            services.AddHangfireServer();

            services.AddHealthCheck(Configuration.GetConnectionString("Admin"), IsSqlServer(databaseEngine));

            // This statement should be kept last to ensure that the IHttpClientFactory and IInferOdsApiVersion services are registered.
            CommonConfigurationInstaller.ConfigureLearningStandards(services).Wait();
        }
Exemple #2
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var executingAssembly = Assembly.GetExecutingAssembly();

            var databaseEngine = Configuration["AppSettings:DatabaseEngine"];

            DbConfiguration.SetConfiguration(new DatabaseEngineDbConfiguration(databaseEngine));

            services.AddDbContext <AdminAppDbContext>(ConfigureForAdminDatabase);
            services.AddDbContext <AdminAppIdentityDbContext>(ConfigureForAdminDatabase);

            services.AddIdentity <AdminAppUser, IdentityRole>()
            .AddEntityFrameworkStores <AdminAppIdentityDbContext>()
            .AddDefaultTokenProviders();

            services.AddControllersWithViews(options =>
            {
                options.Filters.Add(new AuthorizeFilter());
                options.Filters.Add <AutoValidateAntiforgeryTokenAttribute>();
                options.Filters.Add <JsonValidationFilter>();
                options.Filters.Add <HandleAjaxErrorAttribute>();
                options.Filters.Add <SetupRequiredFilter>();
                options.Filters.Add <UserContextFilter>();
                options.Filters.Add <PasswordChangeRequiredFilter>();
                options.Filters.Add <InstanceContextFilter>();
            })
            .AddFluentValidation(
                opt =>
            {
                opt.RegisterValidatorsFromAssembly(executingAssembly);

                opt.ValidatorOptions.DisplayNameResolver = (type, memberInfo, expression)
                                                           => memberInfo?
                                                           .GetCustomAttribute <System.ComponentModel.DataAnnotations.DisplayAttribute>()?.GetName();
            });

            services.Configure <IdentityOptions>(options =>
            {
                options.User.RequireUniqueEmail = true;
            });

            services.ConfigureApplicationCookie(options =>
            {
                options.LoginPath        = "/Identity/Login";
                options.LogoutPath       = "/Identity/LogOut";
                options.AccessDeniedPath = "/Identity/Login";
            });

            services.AddAutoMapper(executingAssembly, typeof(AdminManagementMappingProfile).Assembly);

            services.Configure <AppSettings>(Configuration.GetSection("AppSettings"));
            services.Configure <ConnectionStrings>(Configuration.GetSection("ConnectionStrings"));

            services.AddSignalR();

            var appSettings = new AppSettings();

            Configuration.GetSection("AppSettings").Bind(appSettings);
            ConfigurationAppSettings = appSettings;

            var connectionStrings = new ConnectionStrings();

            Configuration.GetSection("ConnectionStrings").Bind(connectionStrings);
            ConfigurationConnectionStrings = connectionStrings;

            var appStartup = appSettings.AppStartup;

            if (appStartup == "OnPrem")
            {
                new OnPremInstaller().Install(services, appSettings);
            }
            else if (appStartup == "Azure")
            {
                new AzureInstaller().Install(services, appSettings);
            }


            services.AddHangfire(configuration => configuration
                                 .SetDataCompatibilityLevel(CompatibilityLevel.Version_170)
                                 .UseSimpleAssemblyNameTypeSerializer()
                                 .UseRecommendedSerializerSettings());
            HangFireInstance.EnableWithoutSchemaMigration();
            services.AddHangfireServer();

            CommonConfigurationInstaller.ConfigureLearningStandards(services);
        }