.Net工作流elsa-workflows官方文档学习:创建工作流主机(Host)

网页:https://elsa-workflows.github.io/elsa-core/docs/installing-host

工作流正常运转需要注册各种服务。例如,为了触发TimerEvent活动,需要注册TimersHostedService。为了触发HttpRequestEvent活动,需要将RequestHandlerMiddleware <TriggerRequestHandler>中间件添加到ASP.NET Core中间件管道中。如果使用MassTransit(注:这是一个.net分布式应用框架),则将需要注册更多托管服务,以侦听传入的消息。

Startup

下面的例子注册了HTTP和Timer活动:

public void ConfigureServices(IServiceCollection services)
{
    services
        // Required services for Elsa to work. Registers things like `IWorkflowInvoker`.
        .AddElsa()

        // Registers necessary service to handle HTTP requests.
        .AddHttpActivities()

        // Registers a hosted service that periodically invokes workflows containing time-based activities. 
        .AddTimerActivities();
}

下面注册一些相关的中间件:

public void Configure(IApplicationBuilder app)
{
    // Register necessary ASP.NET Core middleware that triggers workflows containing HTTP activities. 
    app.UseHttpActivities();
}

 

上一篇:【ASP.NET Core】运行原理(1):创建WebHost


下一篇:autofac整合MVC