74 lines
2 KiB
C#
74 lines
2 KiB
C#
using Contracts;
|
|
using Microsoft.AspNetCore.HttpOverrides;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.Formatters;
|
|
using Microsoft.Extensions.Options;
|
|
using NLog;
|
|
using Ultimate.Extensions;
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
LogManager.Setup().LoadConfigurationFromXml(string.Concat(Directory.GetCurrentDirectory(), "nlog.config"));
|
|
|
|
builder.Services.ConfigureCors();
|
|
builder.Services.ConfigureIisIntegration();
|
|
builder.Services.ConfigureLoggerService();
|
|
builder.Services.ConfigureRepositoryManager();
|
|
builder.Services.ConfigureServiceManager();
|
|
builder.Services.ConfigureSqlContext(builder.Configuration);
|
|
builder.Services.AddAutoMapper(typeof(Program));
|
|
|
|
builder.Services.Configure<ApiBehaviorOptions>(options =>
|
|
{
|
|
options.SuppressModelStateInvalidFilter = true;
|
|
});
|
|
|
|
builder.Services.AddControllers(config =>
|
|
{
|
|
config.RespectBrowserAcceptHeader = true;
|
|
config.ReturnHttpNotAcceptable = true;
|
|
config.InputFormatters.Insert(0, GetJsonPatchInputFormatter());
|
|
})
|
|
.AddXmlDataContractSerializerFormatters()
|
|
.AddCustomCsvFormatter()
|
|
.AddApplicationPart(typeof(Ultimate.Presentation.AssemblyReference).Assembly);
|
|
|
|
var app = builder.Build();
|
|
|
|
var logger = app.Services.GetRequiredService<ILoggerManager>();
|
|
app.ConfigureExceptionHandler(logger);
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
if (app.Environment.IsProduction())
|
|
app.UseHsts();
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
app.UseAuthorization();
|
|
app.UseStaticFiles();
|
|
app.UseForwardedHeaders(new ForwardedHeadersOptions
|
|
{
|
|
ForwardedHeaders = ForwardedHeaders.All
|
|
});
|
|
|
|
app.UseCors("CorsPolicy");
|
|
app.UseAuthorization();
|
|
|
|
app.MapControllers();
|
|
|
|
app.Run();
|
|
return;
|
|
|
|
NewtonsoftJsonPatchInputFormatter GetJsonPatchInputFormatter() =>
|
|
new ServiceCollection()
|
|
.AddLogging()
|
|
.AddMvc()
|
|
.AddNewtonsoftJson()
|
|
.Services
|
|
.BuildServiceProvider()
|
|
.GetRequiredService<IOptions<MvcOptions>>()
|
|
.Value
|
|
.InputFormatters
|
|
.OfType<NewtonsoftJsonPatchInputFormatter>()
|
|
.First();
|