2020-12-23 01:40:27 +02:00
|
|
|
using AutoMapper;
|
|
|
|
using MediatR;
|
|
|
|
using MediatR.Pipeline;
|
2020-12-21 02:35:47 +02:00
|
|
|
using Microsoft.AspNetCore.Builder;
|
|
|
|
using Microsoft.AspNetCore.Hosting;
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
using Microsoft.Extensions.Hosting;
|
2020-12-23 01:40:27 +02:00
|
|
|
using NDB.Extensions.Swagger;
|
|
|
|
using NDB.Security.Authentication.Identity;
|
|
|
|
using NetworkResurrector.Agent.Application;
|
2020-12-23 01:43:12 +02:00
|
|
|
using NetworkResurrector.Agent.Domain.Data;
|
2020-12-23 01:40:27 +02:00
|
|
|
using Newtonsoft.Json;
|
|
|
|
using System.Reflection;
|
2020-12-21 02:35:47 +02:00
|
|
|
|
|
|
|
namespace NetworkResurrector.Agent
|
|
|
|
{
|
|
|
|
public class Startup
|
|
|
|
{
|
2020-12-23 01:40:27 +02:00
|
|
|
private readonly IConfiguration _configuration;
|
|
|
|
|
2020-12-21 02:35:47 +02:00
|
|
|
public Startup(IConfiguration configuration)
|
|
|
|
{
|
2020-12-23 01:40:27 +02:00
|
|
|
_configuration = configuration;
|
2020-12-21 02:35:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// This method gets called by the runtime. Use this method to add services to the container.
|
|
|
|
public void ConfigureServices(IServiceCollection services)
|
|
|
|
{
|
2020-12-23 01:40:27 +02:00
|
|
|
services.AddControllers()
|
|
|
|
.AddNewtonsoftJson(o => o.SerializerSettings.DateTimeZoneHandling = DateTimeZoneHandling.Utc);
|
|
|
|
|
|
|
|
// Add basic authentication
|
|
|
|
services.AddBasicAuthentication(_configuration.GetSection("IdentityServer")["BaseAddress"]);
|
|
|
|
|
|
|
|
// MediatR
|
|
|
|
services.AddMediatR(GetMediatRAssemblies());
|
|
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPreProcessorBehavior<,>));
|
|
|
|
services.AddScoped(typeof(IPipelineBehavior<,>), typeof(RequestPostProcessorBehavior<,>));
|
|
|
|
|
|
|
|
// AutoMapper
|
|
|
|
services.AddAutoMapper(
|
|
|
|
typeof(Application.Mappings.MappingProfile).Assembly);
|
|
|
|
|
|
|
|
// Swagger
|
|
|
|
services.AddSwagger("NetworkResurrectorAgent API");
|
|
|
|
|
2020-12-23 01:43:12 +02:00
|
|
|
// Data access
|
|
|
|
services.AddDataAccess();
|
|
|
|
|
2020-12-23 01:40:27 +02:00
|
|
|
// Application
|
|
|
|
services.AddApplicationServices();
|
|
|
|
}
|
|
|
|
|
|
|
|
private Assembly[] GetMediatRAssemblies()
|
|
|
|
{
|
|
|
|
var assembly = typeof(Application.Queries.GetMachines).Assembly;
|
|
|
|
return new Assembly[] { assembly };
|
2020-12-21 02:35:47 +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)
|
|
|
|
{
|
2020-12-23 01:40:27 +02:00
|
|
|
// global cors policy
|
|
|
|
app.UseCors(x => x
|
|
|
|
.AllowAnyOrigin()
|
|
|
|
.AllowAnyMethod()
|
|
|
|
.AllowAnyHeader());
|
|
|
|
|
2020-12-21 02:35:47 +02:00
|
|
|
if (env.IsDevelopment())
|
|
|
|
{
|
|
|
|
app.UseDeveloperExceptionPage();
|
|
|
|
}
|
|
|
|
|
|
|
|
app.UseRouting();
|
2020-12-23 01:40:27 +02:00
|
|
|
app.UseAuthentication();
|
2020-12-21 02:35:47 +02:00
|
|
|
app.UseAuthorization();
|
|
|
|
app.UseEndpoints(endpoints =>
|
|
|
|
{
|
|
|
|
endpoints.MapControllers();
|
|
|
|
});
|
2020-12-23 01:40:27 +02:00
|
|
|
app.ConfigureSwagger("NetworkResurrectorAgent API");
|
2020-12-21 02:35:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|