Fix Webhooks persistence provider registration
This commit is contained in:
parent
b8e7368fd9
commit
db82b1e163
|
|
@ -18,15 +18,13 @@ namespace Elsa.Activities.Webhooks.Extensions
|
|||
var services = elsaOptions.Services;
|
||||
|
||||
var optionsBuilder = new WebhookOptionsBuilder(services);
|
||||
|
||||
services.Configure<WebhookOptions>(webhookOptions =>
|
||||
{
|
||||
configureOptions?.Invoke(optionsBuilder);
|
||||
optionsBuilder.ApplyTo(webhookOptions);
|
||||
});
|
||||
configureOptions?.Invoke(optionsBuilder);
|
||||
var options = optionsBuilder.WebhookOptions;
|
||||
|
||||
services.AddSingleton(options);
|
||||
|
||||
services
|
||||
.AddScoped(sp => sp.GetRequiredService<IOptions<WebhookOptions>>().Value.WebhookDefinitionStoreFactory(sp))
|
||||
.AddScoped(sp => sp.GetRequiredService<WebhookOptions>().WebhookDefinitionStoreFactory(sp))
|
||||
.AddActivityTypeProvider<WebhookActivityTypeProvider>()
|
||||
.AddBookmarkProvider<WebhookBookmarkProvider>()
|
||||
.AddNotificationHandlersFrom<EvictWorkflowRegistryCacheHandler>();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Elsa.Activities.Webhooks.Options;
|
||||
using Elsa.Caching;
|
||||
using Elsa.Webhooks.Persistence;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
|
|
@ -8,17 +7,12 @@ namespace Elsa.Activities.Webhooks
|
|||
{
|
||||
public class WebhookOptionsBuilder
|
||||
{
|
||||
public WebhookOptionsBuilder(IServiceCollection services) : this(services, new WebhookOptions())
|
||||
{
|
||||
}
|
||||
|
||||
public WebhookOptionsBuilder(IServiceCollection services, WebhookOptions webhookOptions)
|
||||
public WebhookOptionsBuilder(IServiceCollection services)
|
||||
{
|
||||
Services = services;
|
||||
WebhookOptions = webhookOptions;
|
||||
}
|
||||
|
||||
public WebhookOptions WebhookOptions { get; }
|
||||
public WebhookOptions WebhookOptions { get; } = new();
|
||||
public IServiceCollection Services { get; }
|
||||
|
||||
public WebhookOptionsBuilder UseWebhookDefinitionStore(Func<IServiceProvider, IWebhookDefinitionStore> factory)
|
||||
|
|
@ -26,10 +20,5 @@ namespace Elsa.Activities.Webhooks
|
|||
WebhookOptions.WebhookDefinitionStoreFactory = factory;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void ApplyTo(WebhookOptions webhookOptions)
|
||||
{
|
||||
webhookOptions.WebhookDefinitionStoreFactory = WebhookOptions.WebhookDefinitionStoreFactory;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
using System;
|
||||
using Elsa.Activities.Webhooks;
|
||||
using Elsa.Activities.Webhooks.Options;
|
||||
using Elsa.Options;
|
||||
using Elsa.Services.Startup;
|
||||
using Elsa.Webhooks.Persistence.EntityFramework.Core.Extensions;
|
||||
|
|
@ -31,8 +30,7 @@ namespace Elsa.Webhooks.Persistence.EntityFramework.Core
|
|||
|
||||
var optionsBuilder = new WebhookOptionsBuilder(elsa.Services);
|
||||
optionsBuilder.UseEntityFrameworkPersistence(ef => Configure(ef, connectionString));
|
||||
|
||||
elsa.Services.Configure<WebhookOptions>(options => optionsBuilder.ApplyTo(options));
|
||||
elsa.Services.AddSingleton(optionsBuilder.WebhookOptions);
|
||||
}
|
||||
|
||||
protected virtual string GetDefaultConnectionString() => throw new Exception($"No connection string specified for the {ProviderName} provider");
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using Elsa.Persistence.EntityFramework.Core;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
|
|
@ -8,9 +9,12 @@ namespace Elsa.Persistence.EntityFramework.SqlServer
|
|||
/// <summary>
|
||||
/// Configures the context to use SqlServer.
|
||||
/// </summary>
|
||||
public static DbContextOptionsBuilder UseSqlServer(this DbContextOptionsBuilder builder, string connectionString) =>
|
||||
builder.UseSqlServer(connectionString, db => db
|
||||
.MigrationsAssembly(typeof(SqlServerElsaContextFactory).Assembly.GetName().Name)
|
||||
public static DbContextOptionsBuilder UseSqlServer(this DbContextOptionsBuilder builder, string connectionString, Type? migrationsAssemblyMarker = default)
|
||||
{
|
||||
migrationsAssemblyMarker ??= typeof(SqlServerElsaContextFactory);
|
||||
return builder.UseSqlServer(connectionString, db => db
|
||||
.MigrationsAssembly(migrationsAssemblyMarker.Assembly.GetName().Name)
|
||||
.MigrationsHistoryTable(ElsaContext.MigrationsHistoryTable, ElsaContext.ElsaSchema));
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue