Add feature check and refactor dependencies in Elsa
The commit introduces a new feature check in the `Module` class and refactors the dependencies in MassTransit features. Specifically, it enables querying for a specific feature before configuring the dispatcher endpoints, increasing flexibility and control. In addition, the responsibility for creating `IEndpointChannelFormatter` has been shifted from `MassTransitWorkflowDispatcherFeature` to `MassTransitFeature`, aligning with responsibility distribution. Fixes #5165
This commit is contained in:
parent
298ee70ae2
commit
96ba4f4e1c
|
|
@ -34,6 +34,18 @@ public class Module : IModule
|
|||
/// <inheritdoc />
|
||||
public IDictionary<object, object> Properties { get; } = new Dictionary<object, object>();
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasFeature<T>() where T : class, IFeature
|
||||
{
|
||||
return HasFeature(typeof(T));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasFeature(Type featureType)
|
||||
{
|
||||
return _features.ContainsKey(featureType);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public T Configure<T>(Action<T>? configure = default) where T : class, IFeature
|
||||
=> Configure(module => (T)Activator.CreateInstance(typeof(T), module)!, configure);
|
||||
|
|
|
|||
|
|
@ -76,7 +76,10 @@ public class RabbitMqServiceBusFeature : FeatureBase
|
|||
});
|
||||
}
|
||||
|
||||
configurator.SetupWorkflowDispatcherEndpoints(context);
|
||||
// Only configure the dispatcher endpoints if the Masstransit Workflow Dispatcher feature is enabled.
|
||||
if (Module.HasFeature<MassTransitWorkflowDispatcherFeature>())
|
||||
configurator.SetupWorkflowDispatcherEndpoints(context);
|
||||
|
||||
configurator.ConfigureEndpoints(context, new KebabCaseEndpointNameFormatter("Elsa", false));
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -5,7 +5,9 @@ using Elsa.Extensions;
|
|||
using Elsa.Features.Abstractions;
|
||||
using Elsa.Features.Services;
|
||||
using Elsa.MassTransit.Consumers;
|
||||
using Elsa.MassTransit.Contracts;
|
||||
using Elsa.MassTransit.Extensions;
|
||||
using Elsa.MassTransit.Formatters;
|
||||
using Elsa.MassTransit.Models;
|
||||
using Elsa.MassTransit.Options;
|
||||
using Elsa.MassTransit.Services;
|
||||
|
|
@ -38,6 +40,11 @@ public class MassTransitFeature : FeatureBase
|
|||
/// </summary>
|
||||
public Action<IBusRegistrationConfigurator>? BusConfigurator { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A factory that creates a <see cref="IEndpointChannelFormatter"/>.
|
||||
/// </summary>
|
||||
public Func<IServiceProvider, IEndpointChannelFormatter> ChannelQueueFormatterFactory { get; set; } = _ => new DefaultEndpointChannelFormatter();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Configure()
|
||||
{
|
||||
|
|
@ -48,6 +55,7 @@ public class MassTransitFeature : FeatureBase
|
|||
{
|
||||
var messageTypes = this.GetMessages();
|
||||
|
||||
Services.AddSingleton(ChannelQueueFormatterFactory);
|
||||
Services.Configure<MassTransitWorkflowDispatcherOptions>(x => { });
|
||||
Services.AddActivityProvider<MassTransitActivityTypeProvider>();
|
||||
_runInMemory = BusConfigurator is null;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ using Elsa.Features.Attributes;
|
|||
using Elsa.Features.Services;
|
||||
using Elsa.MassTransit.ConsumerDefinitions;
|
||||
using Elsa.MassTransit.Consumers;
|
||||
using Elsa.MassTransit.Contracts;
|
||||
using Elsa.MassTransit.Formatters;
|
||||
using Elsa.MassTransit.Options;
|
||||
using Elsa.MassTransit.Services;
|
||||
using Elsa.Workflows.Runtime.Contracts;
|
||||
|
|
@ -32,10 +30,6 @@ public class MassTransitWorkflowDispatcherFeature : FeatureBase
|
|||
/// </summary>
|
||||
public Action<MassTransitWorkflowDispatcherOptions>? ConfigureDispatcherOptions { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A factory that creates a <see cref="IEndpointChannelFormatter"/>.
|
||||
/// </summary>
|
||||
public Func<IServiceProvider, IEndpointChannelFormatter> ChannelQueueFormatterFactory { get; set; } = _ => new DefaultEndpointChannelFormatter();
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Configure()
|
||||
|
|
@ -62,7 +56,6 @@ public class MassTransitWorkflowDispatcherFeature : FeatureBase
|
|||
if (ConfigureDispatcherOptions != null)
|
||||
options.Configure(ConfigureDispatcherOptions);
|
||||
|
||||
Services.AddSingleton(ChannelQueueFormatterFactory);
|
||||
Services.AddScoped<MassTransitWorkflowCancellationDispatcher>();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue