generated from finos-labs/project-blueprint
-
Notifications
You must be signed in to change notification settings - Fork 123
Expand file tree
/
Copy pathProgram.cs
More file actions
57 lines (45 loc) · 1.93 KB
/
Program.cs
File metadata and controls
57 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using FluentValidation.AspNetCore;
using Microsoft.OpenApi.Models;
using PeopleService.Core.Infrastructure;
using Serilog;
using System.Reflection;
var builder = WebApplication.CreateBuilder(args);
// Configure port from environment variable
var port = Environment.GetEnvironmentVariable("PEOPLE_SERVICE_PORT") ?? "18089";
builder.WebHost.UseUrls($"http://0.0.0.0:{port}");
// Add services to the container.
builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(
c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "PeopleService.WebApi", Version = "v1" });
var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
c.CustomSchemaIds(t => t.FullName);
c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));
});
builder.Services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(typeof(Program).Assembly));
builder.Services.AddPeopleServiceCore(builder.Configuration.GetSection("PeopleJsonFilePath"));
builder.Services.AddFluentValidationAutoValidation();
builder.Services.AddFluentValidationClientsideAdapters();
builder.Host.UseSerilog((hostContext, services, configuration) =>
{
configuration.WriteTo.Console();
configuration.WriteTo.RollingFile("Logs/PeopleService.log");
});
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "PeopleService.WebApi v1"));
}
app.UseHttpsRedirection();
app.UseAuthorization();
app.MapControllers();
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
app.Run();