# Conflicts: # Samples.sln # src/core/Elsa.Abstractions/Elsa.Abstractions.csproj # src/core/Elsa.Core/Elsa.Core.csproj # src/persistence/Elsa.Persistence.EntityFrameworkCore/Extensions/EFCoreServiceCollectionExtensions.cs # src/providers/Elsa.Persistence.EntityFrameworkCore/Elsa.Persistence.EntityFrameworkCore.csproj # src/providers/Elsa.Persistence.YesSql/DbContexts/DesignTimeDbContextFactoryBase.cs # src/providers/Elsa.Persistence.YesSql/DbContexts/MySqlContext.cs # src/providers/Elsa.Persistence.YesSql/DbContexts/MySqlContextFactory.cs # src/providers/Elsa.Persistence.YesSql/Elsa.Persistence.YesSql.csproj # src/providers/Elsa.Persistence.YesSql/Migrations/MySql/20200113102615_InitialCreate.Designer.cs # src/providers/Elsa.Persistence.YesSql/Migrations/MySql/20200113102615_InitialCreate.cs # src/providers/Elsa.Persistence.YesSql/Migrations/MySql/MySqlContextModelSnapshot.cs # src/samples/Elsa.Samples.Timers/Elsa.Samples.Timers.csproj # src/samples/Sample05/Program.cs # src/samples/Sample08/Sample08.csproj # src/samples/Sample08/Startup.cs # src/samples/Sample14/Program.cs # src/samples/Sample14/Sample14.csproj # src/samples/Sample16/Sample16.csproj # src/samples/Sample18/Program.cs # src/samples/Sample18/Sample18.csproj # src/samples/Sample19/Sample19.csproj # src/samples/Sample19/Startup.cs # src/samples/Sample21/Sample21.csproj # src/samples/Sample21/Startup.cs # src/samples/Sample22/Program.cs # src/samples/Sample22/Sample22.csproj # src/samples/Sample23/Program.cs # src/samples/Sample23/Sample23.csproj
76 lines
3 KiB
C#
76 lines
3 KiB
C#
using System;
|
|
using Elsa.Caching;
|
|
using Elsa.Persistence;
|
|
using Elsa.Persistence.Memory;
|
|
using Elsa.Services;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Rebus.Config;
|
|
using Rebus.DataBus.InMem;
|
|
using Rebus.Persistence.InMem;
|
|
using Rebus.Routing.TypeBased;
|
|
using Rebus.Transport.InMem;
|
|
|
|
namespace Elsa
|
|
{
|
|
public class ElsaOptions
|
|
{
|
|
public ElsaOptions(IServiceCollection services)
|
|
{
|
|
Services = services;
|
|
|
|
WorkflowDefinitionStoreFactory = sp => sp.GetRequiredService<MemoryWorkflowDefinitionStore>();
|
|
WorkflowInstanceStoreFactory = sp => sp.GetRequiredService<MemoryWorkflowInstanceStore>();
|
|
DistributedLockProviderFactory = sp => new DefaultLockProvider();
|
|
SignalFactory = sp => new Signal();
|
|
ServiceBusConfigurer = ConfigureInMemoryServiceBus;
|
|
}
|
|
|
|
public IServiceCollection Services { get; }
|
|
internal Func<IServiceProvider, IWorkflowDefinitionStore> WorkflowDefinitionStoreFactory { get; private set; }
|
|
internal Func<IServiceProvider, IWorkflowInstanceStore> WorkflowInstanceStoreFactory { get; private set; }
|
|
internal Func<IServiceProvider, IDistributedLockProvider> DistributedLockProviderFactory { get; private set; }
|
|
internal Func<IServiceProvider, ISignal> SignalFactory { get; private set; }
|
|
internal Func<RebusConfigurer, IServiceProvider, RebusConfigurer> ServiceBusConfigurer { get; private set; }
|
|
|
|
public ElsaOptions UseWorkflowDefinitionStore(Func<IServiceProvider, IWorkflowDefinitionStore> factory)
|
|
{
|
|
WorkflowDefinitionStoreFactory = factory;
|
|
return this;
|
|
}
|
|
|
|
public ElsaOptions UseWorkflowInstanceStore(Func<IServiceProvider, IWorkflowInstanceStore> factory)
|
|
{
|
|
WorkflowInstanceStoreFactory = factory;
|
|
return this;
|
|
}
|
|
|
|
public ElsaOptions UseDistributedLockProvider(Func<IServiceProvider, IDistributedLockProvider> factory)
|
|
{
|
|
DistributedLockProviderFactory = factory;
|
|
return this;
|
|
}
|
|
|
|
public ElsaOptions UseSignal(Func<IServiceProvider, ISignal> factory)
|
|
{
|
|
SignalFactory = factory;
|
|
return this;
|
|
}
|
|
|
|
public ElsaOptions ConfigureServiceBus(Func<RebusConfigurer, IServiceProvider, RebusConfigurer> configure)
|
|
{
|
|
ServiceBusConfigurer = configure;
|
|
return this;
|
|
}
|
|
|
|
public ElsaOptions ConfigureServiceBus(Func<RebusConfigurer, RebusConfigurer> configure) =>
|
|
ConfigureServiceBus((bus, _) => configure(bus));
|
|
|
|
private static RebusConfigurer ConfigureInMemoryServiceBus(RebusConfigurer rebus, IServiceProvider serviceProvider)
|
|
{
|
|
return rebus
|
|
.Subscriptions(s => s.StoreInMemory(new InMemorySubscriberStore()))
|
|
.Routing(r => r.TypeBased())
|
|
.Transport(t => t.UseInMemoryTransport(new InMemNetwork(), "Messages"));
|
|
}
|
|
}
|
|
} |