using Elsa.Common.Features; using Elsa.Extensions; using Elsa.Features.Abstractions; using Elsa.Features.Attributes; using Elsa.Features.Services; using Elsa.Http.ContentWriters; using Elsa.Http.Handlers; using Elsa.Http.Implementations; using Elsa.Http.Options; using Elsa.Http.Parsers; using Elsa.Http.Services; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; namespace Elsa.Http.Features; [DependsOn(typeof(MemoryCacheFeature))] public class HttpFeature : FeatureBase { public HttpFeature(IModule module) : base(module) { } /// /// A delegate to configure . /// public Action? ConfigureHttpOptions { get; set; } public Func HttpEndpointAuthorizationHandler { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance; public Func HttpEndpointWorkflowFaultHandler { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance; /// /// A delegate to configure the used when by the activity. /// public Action HttpClient { get; set; } = (_, _) => { }; /// /// A delegate to configure the for . /// public Action HttpClientBuilder { get; set; } = _ => { }; /// public override void Configure() { Module.UseWorkflowManagement(management => { management.AddVariableTypes(new[] { typeof(RouteData), typeof(HttpRequest), typeof(HttpResponse) }, "HTTP"); management.AddActivitiesFrom(); }); } /// public override void Apply() { var configureOptions = ConfigureHttpOptions ?? (options => { options.BasePath = "/workflows"; options.BaseUrl = new Uri("http://localhost"); }); Services.Configure(configureOptions); var httpClientBuilder = Services.AddHttpClient(HttpClient); HttpClientBuilder(httpClientBuilder); Services .AddSingleton() .AddSingleton() .AddSingleton() .AddSingleton() .AddNotificationHandlersFrom() .AddHttpContextAccessor() // Add content parsers. .AddSingleton() .AddSingleton() .AddSingleton() // Add HTTP content factories. .AddSingleton() .AddSingleton() .AddSingleton() ; } }