2021-06-18 13:53:10 +00:00
using System.Collections.Generic ;
2021-06-28 20:38:05 +00:00
using Elsa.Server.Hangfire.Extensions ;
using Hangfire ;
2019-11-22 22:07:31 +00:00
using Microsoft.AspNetCore.Builder ;
using Microsoft.AspNetCore.Hosting ;
using Microsoft.Extensions.Configuration ;
using Microsoft.Extensions.DependencyInjection ;
2021-06-02 16:42:57 +00:00
using Microsoft.Extensions.Hosting ;
2019-11-22 22:07:31 +00:00
2020-12-27 10:53:52 +00:00
namespace Elsa.Samples.Server.Host
2019-11-22 22:07:31 +00:00
{
public class Startup
{
public Startup ( IWebHostEnvironment environment , IConfiguration configuration )
{
Environment = environment ;
Configuration = configuration ;
}
2019-11-24 14:25:16 +00:00
private IWebHostEnvironment Environment { get ; }
private IConfiguration Configuration { get ; }
2019-11-22 22:07:31 +00:00
public void ConfigureServices ( IServiceCollection services )
{
var elsaSection = Configuration . GetSection ( "Elsa" ) ;
2021-04-01 16:53:26 +00:00
2021-04-04 13:19:54 +00:00
services . AddControllers ( ) ;
2021-06-19 18:19:05 +00:00
// TODO: Determine startup types based on project references, similar to Orchard Core's Targets.props for Applications and Modules.
// Note that simply loading all referenced assemblies will not include assemblies where no types have been referenced in this project (due to assembly trimming?).
var startups = new [ ]
{
typeof ( Elsa . Activities . Console . Startup ) ,
typeof ( Elsa . Activities . Http . Startup ) ,
typeof ( Elsa . Activities . AzureServiceBus . Startup ) ,
typeof ( Elsa . Activities . Conductor . Startup ) ,
typeof ( Elsa . Activities . UserTask . Startup ) ,
2021-06-20 17:42:28 +00:00
typeof ( Elsa . Activities . Temporal . Quartz . Startup ) ,
typeof ( Elsa . Activities . Temporal . Hangfire . Startup ) ,
typeof ( Elsa . Activities . Email . Startup ) ,
2021-06-28 12:25:48 +00:00
typeof ( Elsa . Activities . Telnyx . Startup ) ,
2021-06-19 18:19:05 +00:00
typeof ( Persistence . EntityFramework . Sqlite . Startup ) ,
typeof ( Persistence . EntityFramework . SqlServer . Startup ) ,
typeof ( Persistence . EntityFramework . MySql . Startup ) ,
typeof ( Persistence . EntityFramework . PostgreSql . Startup ) ,
typeof ( Persistence . MongoDb . Startup ) ,
typeof ( Persistence . YesSql . SqliteStartup ) ,
typeof ( Persistence . YesSql . SqlServerStartup ) ,
typeof ( Persistence . YesSql . MySqlStartup ) ,
typeof ( Persistence . YesSql . PostgreSqlStartup ) ,
2021-06-28 20:38:05 +00:00
typeof ( Elsa . Server . Hangfire . Startup ) ,
2021-06-19 18:19:05 +00:00
typeof ( Elsa . Scripting . JavaScript . Startup ) ,
2021-06-30 15:18:59 +00:00
typeof ( Elsa . Activities . Webhooks . Startup ) ,
typeof ( Webhooks . Persistence . EntityFramework . Sqlite . Startup ) ,
typeof ( Webhooks . Persistence . EntityFramework . SqlServer . Startup ) ,
typeof ( Webhooks . Persistence . EntityFramework . MySql . Startup ) ,
typeof ( Webhooks . Persistence . EntityFramework . PostgreSql . Startup ) ,
typeof ( Webhooks . Persistence . MongoDb . Startup ) ,
typeof ( Webhooks . Persistence . YesSql . SqliteStartup ) ,
typeof ( Webhooks . Persistence . YesSql . SqlServerStartup ) ,
typeof ( Webhooks . Persistence . YesSql . MySqlStartup ) ,
typeof ( Webhooks . Persistence . YesSql . PostgreSqlStartup ) ,
2021-06-19 18:19:05 +00:00
} ;
2019-11-22 22:07:31 +00:00
services
2021-01-31 11:51:51 +00:00
. AddElsa ( elsa = > elsa
2021-05-08 18:44:09 +00:00
. AddActivitiesFrom < Startup > ( )
. AddWorkflowsFrom < Startup > ( )
2021-06-19 18:19:05 +00:00
. AddFeatures ( startups , Configuration , elsaSection . GetSection ( "Features" ) . Get < List < string > > ( ) )
2021-06-28 20:38:05 +00:00
. ConfigureWorkflowChannels ( options = > elsaSection . GetSection ( "WorkflowChannels" ) . Bind ( options ) )
2020-12-26 11:21:08 +00:00
) ;
2021-06-28 20:38:05 +00:00
// Hangfire.
services . AddHangfire ( configuration = > configuration . UseSqlServerStorage ( Configuration . GetConnectionString ( "SqlServer" ) ) ) ;
services . AddHangfireServer ( ( sp , options ) = > options . ConfigureForElsaDispatchers ( sp ) ) ;
2020-01-16 20:23:45 +00:00
2021-04-29 20:43:41 +00:00
// Elsa API endpoints.
2020-01-16 20:23:45 +00:00
services
2020-10-19 20:12:11 +00:00
. AddElsaApiEndpoints ( )
2021-01-19 19:17:14 +00:00
. AddElsaSwagger ( ) ;
2021-03-11 12:17:38 +00:00
2021-02-16 08:55:13 +00:00
// Allow arbitrary client browser apps to access the API for demo purposes only.
// In a production environment, make sure to allow only origins you trust.
2021-03-11 12:17:38 +00:00
services . AddCors ( cors = > cors . AddDefaultPolicy ( policy = > policy . AllowAnyHeader ( ) . AllowAnyMethod ( ) . AllowAnyOrigin ( ) . WithExposedHeaders ( "Content-Disposition" ) ) ) ;
2019-11-22 22:07:31 +00:00
}
public void Configure ( IApplicationBuilder app )
{
if ( Environment . IsDevelopment ( ) )
{
app . UseDeveloperExceptionPage ( ) ;
2020-11-11 20:32:12 +00:00
app . UseSwagger ( ) ;
app . UseSwaggerUI ( c = > c . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "Elsa" ) ) ;
2019-11-22 22:07:31 +00:00
}
2020-02-15 19:32:16 +00:00
app
. UseCors ( )
2021-06-19 10:57:54 +00:00
. UseElsaFeatures ( )
2020-10-20 21:17:08 +00:00
. UseRouting ( )
2021-05-27 15:48:46 +00:00
. UseEndpoints ( endpoints = > { endpoints . MapControllers ( ) ; } ) ;
2019-11-22 22:07:31 +00:00
}
}
}