Example #1
0
        /// <summary>
        ///     Configure method
        /// </summary>
        ///
        /// <remarks>
        ///     This method gets called last.  This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        /// </remarks>
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider host)
        {
            HostEnvironment = env; // cache this for later use (a bit of Tom code)

            // IHostingEnvironment gets injected for us.  It contains all kinds of info about the
            // environment that our app is running under.  The IsDevelopment() method checks for a
            // system enviornment variable called ASPNETCORE_ENVIRONMENT, which can have three
            // values: Development, Staging, or Production.  You can set this var in Project
            // Properties, on the debug tab (it should already be set for you).
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
                app.UseExceptionHandler();
                app.UseHsts();
            }

            app.UseHttpsRedirection();

            app.UseMvc();

            if (HostEnvironment.IsDevelopment())
            {
                IAppDbContext appDbContext = host.GetRequiredService <IAppDbContext>();
                appDbContext.AddMockData();
            }
        }