2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Services;
|
2022-10-25 13:52:55 +00:00
|
|
|
using Elsa.Http.ContentWriters;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Handlers;
|
|
|
|
|
using Elsa.Http.Implementations;
|
|
|
|
|
using Elsa.Http.Options;
|
2022-10-25 13:52:55 +00:00
|
|
|
using Elsa.Http.Parsers;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Services;
|
|
|
|
|
using Elsa.Mediator.Extensions;
|
|
|
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
namespace Elsa.Http.Features;
|
2022-05-26 10:47:31 +00:00
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
public class HttpFeature : FeatureBase
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
2022-05-27 10:36:39 +00:00
|
|
|
public HttpFeature(IModule module) : base(module)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2022-11-19 21:30:43 +00:00
|
|
|
public Action<HttpActivityOptions>? ConfigureHttpOptions { get; set; }
|
2022-05-26 10:47:31 +00:00
|
|
|
public Func<IServiceProvider, IHttpEndpointAuthorizationHandler> HttpEndpointAuthorizationHandlerFactory { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance<AllowAnonymousHttpEndpointAuthorizationHandler>;
|
|
|
|
|
public Func<IServiceProvider, IHttpEndpointWorkflowFaultHandler> HttpEndpointWorkflowFaultHandlerFactory { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance<DefaultHttpEndpointWorkflowFaultHandler>;
|
2022-11-19 21:30:43 +00:00
|
|
|
|
|
|
|
|
public HttpFeature WithHttpOptions(Action<HttpActivityOptions> value)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
2022-11-19 21:30:43 +00:00
|
|
|
ConfigureHttpOptions = value;
|
2022-05-26 10:47:31 +00:00
|
|
|
return this;
|
|
|
|
|
}
|
2022-11-19 21:30:43 +00:00
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
public HttpFeature WithAuthorizationHandlerFactory(Func<IServiceProvider, IHttpEndpointAuthorizationHandler> value)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
|
|
|
|
HttpEndpointAuthorizationHandlerFactory = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
public HttpFeature WithWorkflowFaultHandlerFactory(Func<IServiceProvider, IHttpEndpointWorkflowFaultHandler> value)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
|
|
|
|
HttpEndpointWorkflowFaultHandlerFactory = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Apply()
|
|
|
|
|
{
|
2022-11-19 21:30:43 +00:00
|
|
|
var configureOptions = ConfigureHttpOptions ?? (options =>
|
|
|
|
|
{
|
|
|
|
|
options.BasePath = "/workflows";
|
|
|
|
|
options.BaseUrl = new Uri("http://localhost");
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Services.Configure(configureOptions);
|
2022-05-26 10:47:31 +00:00
|
|
|
|
|
|
|
|
Services
|
2022-10-25 13:52:55 +00:00
|
|
|
.AddHttpClient()
|
2022-05-26 10:47:31 +00:00
|
|
|
.AddSingleton<IRouteMatcher, RouteMatcher>()
|
|
|
|
|
.AddSingleton<IRouteTable, RouteTable>()
|
2022-11-19 21:30:43 +00:00
|
|
|
.AddSingleton<IAbsoluteUrlProvider, DefaultAbsoluteUrlProvider>()
|
2022-05-26 10:47:31 +00:00
|
|
|
.AddNotificationHandlersFrom<UpdateRouteTable>()
|
2022-10-25 13:52:55 +00:00
|
|
|
.AddHttpContextAccessor()
|
|
|
|
|
|
|
|
|
|
// Add Content Parsers
|
|
|
|
|
.AddSingleton<IHttpResponseContentReader, JsonElementHttpResponseContentReader>()
|
|
|
|
|
|
|
|
|
|
//Add Request Content Writers
|
|
|
|
|
.AddSingleton<IHttpRequestContentWriter, StringHttpRequestContentWriter>()
|
|
|
|
|
.AddSingleton<IHttpRequestContentWriter, FormUrlEncodedHttpRequestContentWriter>()
|
|
|
|
|
;
|
2022-05-26 10:47:31 +00:00
|
|
|
}
|
|
|
|
|
}
|