More features
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
|
||||
using System.Reflection;
|
||||
using DCGEngine.Database.Configuration;
|
||||
using System.Text.Json.Serialization;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using SVSim.Database;
|
||||
using SVSim.Database.Models;
|
||||
using SVSim.Database.Repositories.Card;
|
||||
using SVSim.Database.Repositories.Collectibles;
|
||||
using SVSim.Database.Repositories.Deck;
|
||||
using SVSim.Database.Repositories.Globals;
|
||||
using SVSim.Database.Repositories.Viewer;
|
||||
using SVSim.EmulatedEntrypoint.Middlewares;
|
||||
@@ -21,7 +20,14 @@ public class Program
|
||||
|
||||
// Add services to the container.
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddControllers().AddJsonOptions(opt =>
|
||||
{
|
||||
// Production omits null/optional fields entirely; the client uses
|
||||
// `Keys.Contains(name)` as a presence check and calls `.ToInt()` (etc.) on the
|
||||
// value without a null guard. Emitting `"key":null` makes Contains return true and
|
||||
// crashes the client. Match prod by dropping nulls during serialization.
|
||||
opt.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
|
||||
});
|
||||
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
@@ -38,16 +44,14 @@ public class Program
|
||||
});
|
||||
builder.Services.AddTransient<IViewerRepository, ViewerRepository>();
|
||||
builder.Services.AddTransient<ICardRepository, CardRepository>();
|
||||
builder.Services.AddTransient<ICollectionRepository, CollectionRepository>();
|
||||
builder.Services.AddTransient<IGlobalsRepository, GlobalsRepository>();
|
||||
builder.Services.AddTransient<IDeckRepository, DeckRepository>();
|
||||
|
||||
#endregion
|
||||
|
||||
builder.Services.AddTransient<ShadowverseTranslationMiddleware>();
|
||||
builder.Services.AddTransient<SessionidMappingMiddleware>();
|
||||
builder.Services.Configure<DCGEDatabaseConfiguration>(opt =>
|
||||
{
|
||||
opt.DbSetSearchAssemblies = new List<Assembly> { Assembly.GetAssembly(typeof(SVSimDbContext)) };
|
||||
});
|
||||
builder.Services.AddSingleton<ShadowverseSessionService>();
|
||||
builder.Services.AddSingleton<SteamSessionService>();
|
||||
builder.Services.AddAuthentication()
|
||||
@@ -60,11 +64,16 @@ public class Program
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Update database
|
||||
// Update database (skipped for non-relational providers, e.g. InMemory in tests, and
|
||||
// skipped under the "Testing" environment where the test fixture has already called
|
||||
// EnsureCreated against a SQLite in-memory DB — the Postgres migrations would fail there).
|
||||
using (var scope = app.Services.CreateScope())
|
||||
{
|
||||
var dbContext = scope.ServiceProvider.GetRequiredService<SVSimDbContext>();
|
||||
dbContext.UpdateDatabase();
|
||||
if (dbContext.Database.IsRelational() && !app.Environment.IsEnvironment("Testing"))
|
||||
{
|
||||
dbContext.UpdateDatabase();
|
||||
}
|
||||
}
|
||||
|
||||
app.UseHttpLogging();
|
||||
|
||||
Reference in New Issue
Block a user