2022-05-26 10:47:31 +00:00
|
|
|
using System;
|
2022-05-27 10:36:39 +00:00
|
|
|
using Elsa.Features.Abstractions;
|
|
|
|
|
using Elsa.Features.Services;
|
2022-05-26 10:47:31 +00:00
|
|
|
using Elsa.Http.Handlers;
|
|
|
|
|
using Elsa.Http.Implementations;
|
|
|
|
|
using Elsa.Http.Options;
|
|
|
|
|
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
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string BasePath { get; set; } = "/workflows";
|
|
|
|
|
public Func<IServiceProvider, IHttpEndpointAuthorizationHandler> HttpEndpointAuthorizationHandlerFactory { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance<AllowAnonymousHttpEndpointAuthorizationHandler>;
|
|
|
|
|
public Func<IServiceProvider, IHttpEndpointWorkflowFaultHandler> HttpEndpointWorkflowFaultHandlerFactory { get; set; } = ActivatorUtilities.GetServiceOrCreateInstance<DefaultHttpEndpointWorkflowFaultHandler>;
|
|
|
|
|
|
2022-05-27 10:36:39 +00:00
|
|
|
public HttpFeature WithBasePath(string value)
|
2022-05-26 10:47:31 +00:00
|
|
|
{
|
|
|
|
|
BasePath = value;
|
|
|
|
|
return this;
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
Services.Configure<HttpActivityOptions>(options => options.BasePath = BasePath);
|
|
|
|
|
|
|
|
|
|
Services
|
|
|
|
|
.AddSingleton<IRouteMatcher, RouteMatcher>()
|
|
|
|
|
.AddSingleton<IRouteTable, RouteTable>()
|
|
|
|
|
.AddNotificationHandlersFrom<UpdateRouteTable>()
|
|
|
|
|
.AddHttpContextAccessor();
|
|
|
|
|
}
|
|
|
|
|
}
|