CodeLiturgy.Dashboard/CodeLiturgy.Views/Startup.cs

110 lines
3.3 KiB
C#
Raw Permalink Normal View History

2022-09-29 02:37:24 +03:00
using System.Globalization;
2022-11-26 01:35:47 +03:00
using System.Reflection;
2022-11-18 03:15:53 +03:00
using CodeLiturgy.Data.Auth;
2022-11-26 01:35:47 +03:00
using CodeLiturgy.Startup.Application;
2022-12-06 17:33:12 +03:00
using CodeLiturgy.Views.Augeas;
2022-10-30 19:48:24 +03:00
using CodeLiturgy.Views.Utils;
2022-09-29 02:37:24 +03:00
using Microsoft.AspNetCore.Authentication.Cookies;
using Microsoft.AspNetCore.Localization;
2022-11-26 01:35:47 +03:00
using Microsoft.OpenApi.Models;
2022-09-29 02:37:24 +03:00
2022-10-30 19:48:24 +03:00
namespace CodeLiturgy.Views;
2022-09-29 02:37:24 +03:00
public class Startup
{
private readonly IConfiguration _configuration;
private readonly IWebHostEnvironment _environment;
/// <summary>
/// Startup ctor
/// </summary>
public Startup(IConfiguration configuration, IWebHostEnvironment hostEnvironment)
{
_configuration = configuration;
_environment = hostEnvironment;
}
/// <summary>
/// Configure Services
/// </summary>
/// <param name="services">Dependency injection</param>
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton<LayoutCache>();
// Add services to the container.
services.Configure<CookiePolicyOptions>(options =>
{
// This lambda determines whether user consent for non-essential cookies is needed for a given request.
options.CheckConsentNeeded = context => true;
options.MinimumSameSitePolicy = SameSiteMode.None;
});
services.AddLogging(builder =>
{
builder.AddSimpleConsole();
});
2022-11-26 01:35:47 +03:00
if (_environment.IsDevelopment())
{
services.ConfigureSwagger();
}
2022-12-06 17:33:12 +03:00
services.AddSingleton<AugeasManager>();
2022-09-29 02:37:24 +03:00
services.AddControllersWithViews(x => x.EnableEndpointRouting = false);
2022-10-27 20:13:02 +03:00
services.AddAuthServerServices(_configuration, _environment);
2022-11-13 14:27:48 +03:00
services.PreparePostgresqlDatabasePool(_configuration, _environment);
2022-09-29 02:37:24 +03:00
}
/// <summary>
/// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
/// </summary>
/// <param name="app">Object with the necessary data to configure an application's request pipeline</param>
/// <param name="env">Provides information about the web hosting environment an application is running in.</param>
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// Configure the HTTP request pipeline.
2022-11-26 01:35:47 +03:00
if (!_environment.IsDevelopment())
2022-09-29 02:37:24 +03:00
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
2022-11-26 01:35:47 +03:00
2022-09-29 02:37:24 +03:00
}
2022-11-26 01:35:47 +03:00
app.UseSwagger();
app.UseSwaggerUI(c =>
{
2022-12-02 05:31:11 +03:00
c.RoutePrefix = "api/swagger";
2022-11-26 01:35:47 +03:00
c.SwaggerEndpoint("/swagger/v1/swagger.json", "CodeLiturgy.Views v1");
});
2022-09-29 02:37:24 +03:00
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.UseRequestLocalization(options =>
{
var supportedCultures = CultureInfo.GetCultures(CultureTypes.AllCultures);
options.DefaultRequestCulture = new RequestCulture("en-GB");
options.SupportedCultures = supportedCultures;
options.SupportedUICultures = supportedCultures;
});
app.UseAuthentication();
app.UseAuthorization();
app.UseSession();
2022-10-27 20:13:02 +03:00
2022-09-29 02:37:24 +03:00
app.UseMvcWithDefaultRoute();
}
}