-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
69 lines (51 loc) · 2.15 KB
/
Program.cs
File metadata and controls
69 lines (51 loc) · 2.15 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
58
59
60
61
62
63
64
65
66
67
68
69
using MarsUndiscoveredApi;
using MarsUndiscoveredApi.Models;
using MarsUndiscoveredApi.Services;
using MarsUndiscoveredApi.Extensions;
using Serilog;
try
{
var builder = WebApplication.CreateBuilder(args);
builder.Host.UseSerilog();
var telemetryConnectionString = Environment.GetEnvironmentVariable(Constants.MarsUndiscoveredTelemetryConnectionString);
if (!String.IsNullOrEmpty(telemetryConnectionString))
builder.Services.AddApplicationInsightsTelemetry(c => c.ConnectionString = telemetryConnectionString);
else
builder.Services.AddApplicationInsightsTelemetry();
Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(builder.Configuration)
.CreateLogger();
builder.Services.AddSingleton(Log.Logger);
// Add services to the container.
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var databaseSettings = new DatabaseSettings();
var databaseFileConfiguration = builder.Configuration.GetSection("MarsUndiscoveredDatabase");
databaseSettings.ConnectionString = databaseFileConfiguration.GetValueOrEnvironmentVariable(Constants.MarsUndiscoveredDbConnectionString);
databaseSettings.DatabaseName = databaseFileConfiguration.GetValueOrEnvironmentVariable(Constants.MarsUndiscoveredDbName);
databaseSettings.MorgueCollectionName = databaseFileConfiguration.GetValueOrEnvironmentVariable(Constants.MarsUndiscoveredMorgueCollectionName);
builder.Services.AddSingleton(databaseSettings);
builder.Services.AddSingleton<IMorgueService, MorgueService>();
var app = builder.Build();
// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
app.UseSwagger();
app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); });
}
app.UseHttpsRedirection();
app.UseStaticFiles();
app.MapControllers();
app.MapFallbackToFile("index.html");
app.Run();
}
catch (Exception ex)
{
Log.Fatal(ex, "Application startup failed");
}
finally
{
Log.CloseAndFlush();
}