Salmon/Salmon.Web/Program.cs
2024-05-17 18:11:36 +02:00

66 lines
1.7 KiB
C#

using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Web;
using Salmon.Web;
using Salmon.Web.Data;
using System.Text.Json.Serialization;
Salmon.Core.Instance CoreInstance;
var builder = WebApplication.CreateBuilder(args);
builder.Services
.AddControllers()
.AddJsonOptions((options) =>
{
options.JsonSerializerOptions.Converters.Add(new TripletJsonConverter());
});
builder.Services.AddSwaggerGen();
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddServerSideBlazor();
builder.Services.AddBlazorBootstrap();
MongoDbInterface dbInterface = new();
while (!await dbInterface.Test())
{
Console.WriteLine("Connection to mongodb failed, retrying...");
await Task.Delay(500);
}
builder.Services.AddSingleton(CoreInstance = new Salmon.Core.Instance(dbInterface));
builder.Services.AddSingleton<WeatherForecastService>();
Console.WriteLine("Connected to Mongo database.");
CoreInstance.Persistence = dbInterface;
CoreInstance.State.History = dbInterface;
await CoreInstance.State.PopulateWithHistory();
builder.Services.AddSingleton(dbInterface);
builder.Services.AddSingleton(new CurrentSoftwareRefresher(CoreInstance));
var app = builder.Build();
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Blazor API V1");
});
app.UseHttpsRedirection();
app.UseStaticFiles();
app.UseRouting();
app.MapControllers();
app.MapBlazorHub();
app.MapFallbackToPage("/_Host");
app.Run();