Skip to content

Instantly share code, notes, and snippets.

@gnzandrs
Created April 18, 2019 15:50
Show Gist options
  • Save gnzandrs/afa975022a0319353896374946c6768c to your computer and use it in GitHub Desktop.
Save gnzandrs/afa975022a0319353896374946c6768c to your computer and use it in GitHub Desktop.

Revisions

  1. gnzandrs created this gist Apr 18, 2019.
    45 changes: 45 additions & 0 deletions medium-startup.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    using Microsoft.AspNetCore.Builder;
    using Microsoft.AspNetCore.Hosting;
    using Microsoft.AspNetCore.Mvc;
    using Microsoft.EntityFrameworkCore;
    using Microsoft.Extensions.Configuration;
    using Microsoft.Extensions.DependencyInjection;
    using DotNetApi.Models;

    namespace DotNetApi
    {
    public class Startup
    {
    public Startup(IConfiguration configuration)
    {
    Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
    services.AddDbContext<dbContext>(options =>
    options.UseSqlServer(Configuration.GetConnectionString("DefaultConnection")));
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
    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.UseHsts();
    }

    app.UseHttpsRedirection();
    app.UseMvc();
    }
    }
    }