Fase 3b: de Hero bewaart zijn foto's in de bibliotheektabel (schakelaar uit), HeroImages blijft een kopie, controle bij het opstarten, FK-migratie met Down
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Diagnostics;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
@@ -26,12 +28,21 @@ public class HeroModule : IModule
|
||||
|
||||
public void RegisterServices(IServiceCollection services)
|
||||
{
|
||||
// Where the photos are stored (media library phase 3b): off = HeroImages, on = the library's MediaAssets table.
|
||||
services.AddSingleton(serviceProvider => new HeroStorage(serviceProvider.GetRequiredService<IConfiguration>().GetValue<bool>("Media:Library:HeroPhotosInLibrary")));
|
||||
services.AddDbContext<HeroDbContext>((serviceProvider, options) =>
|
||||
{
|
||||
var config = serviceProvider.GetRequiredService<IConfiguration>();
|
||||
options.UseMySQL(config.GetConnectionString("DefaultConnection")!);
|
||||
options.ReplaceService<IHistoryRepository, NonLockingMySQLHistoryRepository>();
|
||||
options.ReplaceService<IModelCacheKeyFactory, HeroModelCacheKeyFactory>();
|
||||
if (serviceProvider.GetRequiredService<HeroStorage>().PhotosInLibrary)
|
||||
{
|
||||
// The model differs from the migrations snapshot on purpose (the photos' table belongs to the library).
|
||||
options.ConfigureWarnings(warnings => warnings.Ignore(RelationalEventId.PendingModelChangesWarning));
|
||||
}
|
||||
});
|
||||
services.AddScoped<IHeroLegacyImageMirror, HeroLegacyImageMirror>();
|
||||
|
||||
services.AddCmsTextsFrom(typeof(HeroModule).Assembly);
|
||||
services.AddOptions<HeroOptions>().Configure<IConfiguration>((options, configuration) =>
|
||||
@@ -63,5 +74,6 @@ public class HeroModule : IModule
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<HeroDbContext>();
|
||||
db.Database.Migrate();
|
||||
HeroPhotoStorageGuard.VerifyAsync(db, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user