using System.Diagnostics.CodeAnalysis; using Microsoft.AspNetCore.Builder; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Migrations; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using SlpModularCms.Core.Hosting; using SlpModularCms.Core.Hosting.Website; using SlpModularCms.Core.Media; using SlpModularCms.Core.Media.Library; using SlpModularCms.Core.Media.Magick; using SlpModularCms.Core.Modules; using SlpModularCms.Core.Texts; using SlpModularCms.Modules.Hero.Data; using SlpModularCms.Modules.Hero.Repositories; using SlpModularCms.Modules.Hero.Services; namespace SlpModularCms.Modules.Hero; /// The manageable hero of a website: texts, buttons, slides with images; images are processed and served by the host. [ExcludeFromCodeCoverage] public class HeroModule : IModule { public string Name => "Hero"; public string Version => "1.0.0"; public void RegisterServices(IServiceCollection services) { services.AddDbContext((serviceProvider, options) => { var config = serviceProvider.GetRequiredService(); options.UseMySQL(config.GetConnectionString("DefaultConnection")!); options.ReplaceService(); }); services.AddCmsTextsFrom(typeof(HeroModule).Assembly); services.AddOptions().Configure((options, configuration) => configuration.GetSection(HeroOptions.SectionName).Bind(options)); // Image processing and the media area this module owns (served at /media/hero/...). services.AddCmsMediaArea(HeroMapping.Area); services.AddMagickImageProcessor(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddScoped(provider => provider.GetRequiredService()); services.AddScoped(); services.AddScoped(); services.AddScoped(); services.AddSingleton(); services.AddHostedService(); services.AddScoped(); services.AddHostedService(); } public void UseModule(IApplicationBuilder app) { using var scope = app.ApplicationServices.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); HeroImagesDropGuard.Verify(db); db.Database.Migrate(); } }