Fase 3c (code, nog niet uitgerold): foto's altijd in de bibliotheektabel, HeroImages-migratie met controle, schakelaars en hulpmiddelen weg
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
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;
|
||||
@@ -28,21 +26,12 @@ 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) =>
|
||||
@@ -58,8 +47,6 @@ public class HeroModule : IModule
|
||||
services.AddScoped<IHeroImageService, HeroImageService>();
|
||||
services.AddScoped<HeroMediaUsageProvider>();
|
||||
services.AddScoped<IMediaUsageProvider>(provider => provider.GetRequiredService<HeroMediaUsageProvider>());
|
||||
services.AddScoped<IMediaReadVerifier>(provider => provider.GetRequiredService<HeroMediaUsageProvider>());
|
||||
services.AddScoped<IMediaMigrationSource, HeroMediaMigrationSource>();
|
||||
services.AddScoped<IHeroPageModel, HeroPageModel>();
|
||||
services.AddScoped<IHtmlPageTransform, HeroHtmlTransform>();
|
||||
services.AddScoped<ICmsDataBlockContributor, HeroDataContributor>();
|
||||
@@ -73,7 +60,7 @@ public class HeroModule : IModule
|
||||
{
|
||||
using var scope = app.ApplicationServices.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<HeroDbContext>();
|
||||
HeroImagesDropGuard.Verify(db);
|
||||
db.Database.Migrate();
|
||||
HeroPhotoStorageGuard.VerifyAsync(db, CancellationToken.None).GetAwaiter().GetResult();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user