proxmox-connector/src/server/ProxmoxConnector.Server/Startup.cs

80 lines
2.8 KiB
C#
Raw Normal View History

2022-03-03 12:22:23 +02:00
using MediatR;
using MediatR.Pipeline;
2022-01-19 15:51:28 +02:00
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
2022-03-02 09:40:51 +02:00
using NDB.Extensions.Swagger;
using NDB.Extensions.Swagger.Constants;
using NDB.Infrastructure.DatabaseMigration;
using NDB.Security.Authentication.Identity;
using Newtonsoft.Json;
using ProxmoxConnector.Server.Application;
using ProxmoxConnector.Server.Domain.Abstractions;
using ProxmoxConnector.Server.Services;
2022-03-03 12:22:23 +02:00
using System.Reflection;
2022-01-19 15:51:28 +02:00
namespace ProxmoxConnector.Server
{
public class Startup
{
2022-03-02 09:40:51 +02:00
private readonly IConfiguration _configuration;
2022-01-19 15:51:28 +02:00
public Startup(IConfiguration configuration)
{
2022-03-02 09:40:51 +02:00
_configuration = configuration;
2022-01-19 15:51:28 +02:00
}
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
2022-03-02 09:40:51 +02:00
services.AddControllers().AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
2022-01-19 15:51:28 +02:00
2022-03-02 09:40:51 +02:00
// Add basic authentication
services.AddIdentityAuthentication(_configuration.GetSection("IdentityServer")["BaseAddress"]);
2022-03-03 12:22:23 +02:00
// MediatR
services.AddMediatR(GetMediatRAssemblies());
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
2022-03-02 09:40:51 +02:00
services.AddHttpContextAccessor();
services.AddScoped<IUserService, UserService>();
services.AddSwagger("ProxmoxConnector.Server", AuthorizationType.InhouseIdentity);
services.AddAutoMapper(typeof(Application.Mappings.MappingProfile).Assembly);
var workspace = _configuration.GetValue<string>("Workspace");
services.AddMigration(workspace: workspace);
//services.AddDataAccess();
services.AddApplicationServices();
2022-01-19 15:51:28 +02:00
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
2022-03-02 09:40:51 +02:00
app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());
app.UseExceptionHandler("/error");
2022-01-19 15:51:28 +02:00
2022-03-02 09:40:51 +02:00
app.ConfigureSwagger("CDN.Server v1");
2022-01-19 15:51:28 +02:00
2022-03-02 09:40:51 +02:00
app.UseRouting();
app.UseAuthentication();
2022-01-19 15:51:28 +02:00
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
});
2022-03-02 09:40:51 +02:00
app.UseMigration();
2022-01-19 15:51:28 +02:00
}
2022-03-03 12:22:23 +02:00
private Assembly[] GetMediatRAssemblies()
{
var assembly = typeof(Application.Queries.System.GetSystemVersion).Assembly;
return new Assembly[] { assembly };
}
2022-01-19 15:51:28 +02:00
}
}