| | | 1 | | using System.Reflection; |
| | | 2 | | |
| | | 3 | | namespace Elsa.Workflows.Management; |
| | | 4 | | |
| | | 5 | | /// <summary> |
| | | 6 | | /// Provides an extensibility hook to resolve values for host method parameters. |
| | | 7 | | /// Implementations can decide to resolve from workflow inputs, DI, context, or any other source. |
| | | 8 | | /// </summary> |
| | | 9 | | public interface IHostMethodParameterValueProvider |
| | | 10 | | { |
| | | 11 | | /// <summary> |
| | | 12 | | /// Attempts to provide a value for the specified parameter. |
| | | 13 | | /// Return a handled result when a value was provided (including <c>null</c>), otherwise return <see cref="HostMetho |
| | | 14 | | /// to let other providers handle it. |
| | | 15 | | /// </summary> |
| | | 16 | | ValueTask<HostMethodParameterValueProviderResult> GetValueAsync(HostMethodParameterValueProviderContext context); |
| | | 17 | | } |
| | | 18 | | |
| | | 19 | | /// <summary> |
| | | 20 | | /// Result returned by <see cref="IHostMethodParameterValueProvider"/>. |
| | | 21 | | /// </summary> |
| | 0 | 22 | | public readonly record struct HostMethodParameterValueProviderResult(bool Handled, object? Value) |
| | | 23 | | { |
| | 0 | 24 | | public static HostMethodParameterValueProviderResult Unhandled { get; } = new(false, null); |
| | 0 | 25 | | public static HostMethodParameterValueProviderResult HandledValue(object? value) => new(true, value); |
| | | 26 | | } |
| | | 27 | | |
| | | 28 | | /// <summary> |
| | | 29 | | /// Context passed to <see cref="IHostMethodParameterValueProvider"/>. |
| | | 30 | | /// </summary> |
| | | 31 | | public record HostMethodParameterValueProviderContext( |
| | | 32 | | IServiceProvider ServiceProvider, |
| | | 33 | | ActivityExecutionContext ActivityExecutionContext, |
| | | 34 | | IReadOnlyCollection<Elsa.Workflows.Models.InputDescriptor> InputDescriptors, |
| | | 35 | | IActivity Activity, |
| | | 36 | | ParameterInfo Parameter, |
| | | 37 | | CancellationToken CancellationToken) |
| | | 38 | | { |
| | | 39 | | public string ParameterName => Parameter.Name ?? string.Empty; |
| | | 40 | | } |