* Added migrations to install EF Core OpenIddict tables * Handle Install of ef core data (Needs to be outside of transaction * Cleanup and renaming, as these things will be reused for more than openiddict in the future * Cleanup * Extract db context setup * Minor cleanup --------- Co-authored-by: Nikolaj <nikolajlauridsen@protonmail.ch>
57 lines
2.0 KiB
C#
57 lines
2.0 KiB
C#
using Microsoft.Extensions.DependencyInjection;
|
|
using Umbraco.Cms.Core.Composing;
|
|
using Umbraco.Cms.Core.DependencyInjection;
|
|
using Umbraco.Cms.Core.Events;
|
|
using Umbraco.Cms.Core.Notifications;
|
|
using Umbraco.Cms.Infrastructure.Migrations;
|
|
using Umbraco.Cms.Infrastructure.Migrations.Notifications;
|
|
using Umbraco.Cms.Persistence.EFCore;
|
|
|
|
namespace Umbraco.Cms.Persistence.EFCore.Composition;
|
|
|
|
public class UmbracoEFCoreComposer : IComposer
|
|
{
|
|
public void Compose(IUmbracoBuilder builder)
|
|
{
|
|
builder.Services.AddSingleton<IEFCoreMigrationExecutor, EfCoreMigrationExecutor>();
|
|
|
|
builder.AddNotificationAsyncHandler<DatabaseSchemaAndDataCreatedNotification, EFCoreCreateTablesNotificationHandler>();
|
|
builder.AddNotificationAsyncHandler<UnattendedInstallNotification, EFCoreCreateTablesNotificationHandler>();
|
|
builder.Services.AddOpenIddict()
|
|
|
|
// Register the OpenIddict core components.
|
|
.AddCore(options =>
|
|
{
|
|
options
|
|
.UseEntityFrameworkCore()
|
|
.UseDbContext<UmbracoDbContext>();
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
public class EFCoreCreateTablesNotificationHandler : INotificationAsyncHandler<DatabaseSchemaAndDataCreatedNotification>, INotificationAsyncHandler<UnattendedInstallNotification>
|
|
{
|
|
private readonly IEFCoreMigrationExecutor _iefCoreMigrationExecutor;
|
|
|
|
public EFCoreCreateTablesNotificationHandler(IEFCoreMigrationExecutor iefCoreMigrationExecutor)
|
|
{
|
|
_iefCoreMigrationExecutor = iefCoreMigrationExecutor;
|
|
}
|
|
|
|
public async Task HandleAsync(UnattendedInstallNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
await HandleAsync();
|
|
}
|
|
|
|
public async Task HandleAsync(DatabaseSchemaAndDataCreatedNotification notification, CancellationToken cancellationToken)
|
|
{
|
|
await HandleAsync();
|
|
}
|
|
|
|
private async Task HandleAsync()
|
|
{
|
|
await _iefCoreMigrationExecutor.ExecuteAllMigrationsAsync();
|
|
}
|
|
}
|