Files
EstusShots-Net/EstusShots.Server/Startup.cs

59 lines
1.9 KiB
C#

using AutoMapper;
using EstusShots.Server.Services;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using IHostingEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
namespace EstusShots.Server
{
public class Startup
{
public IConfiguration Configuration { get; }
private bool IsDevelopment { get; set; }
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<EstusShotsContext>(
opt => opt.UseInMemoryDatabase("debug.db"));
services.AddAutoMapper(typeof(Startup));
services.AddControllers().AddJsonOptions(options =>
{
if (IsDevelopment)
{
options.JsonSerializerOptions.WriteIndented = true;
}
});
services.AddScoped<SeasonsService>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
IsDevelopment = env.IsDevelopment();
if (IsDevelopment)
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHttpsRedirection();
}
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints => { endpoints.MapControllers(); });
}
}
}