Beispiel #1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            // Get config options
            services.AddConfigRegistration(Configuration);

            // Configure database
            services.AddDatabase(Configuration, Logging, env);

            // Configure application services
            services.AddServiceRegistration();

            // Adds profiler service for performance checking
            services.AddMiniProfiler();

            // Adds response caching and compression
            services.AddCachingAndCompression();

            // Configure AAD
            services.AddAzureADAuth(Configuration);

            // Adds server side Application Insights
            services.AddApplicationInsightsTelemetry();

            // Configure cookie policy options
            services.ConfigureCookiePolicy();

            // Configure antiforgery token options
            services.AddAntiforgery(opts => opts.Cookie.Name = CookieNames.AntiForgery);

            // Add controllers + views instead of razor pages
            services.AddControllersWithViews();

            // Add/configure MVC
            services.AddMvc(options =>
            {
                // require user is logged in to access anything by default unless in dev
                if (env != "Development")
                {
                    AuthOptions.AddAuthOptions(options);
                }

                // Automatically add an anti-forgery token to any http request method that alters server state
                options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());

                // add cache profiles
                CacheProfiles.AddCacheProfiles(options);
            });
        }