2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Management;
|
2023-03-24 10:11:27 +00:00
|
|
|
using Elsa.EntityFrameworkCore.Modules.Runtime;
|
2022-12-30 12:11:29 +00:00
|
|
|
using Elsa.Extensions;
|
|
|
|
|
|
|
|
|
|
var builder = WebApplication.CreateBuilder(args);
|
|
|
|
|
|
|
|
|
|
// Add services to the container.
|
|
|
|
|
builder.Services.AddElsa(elsa =>
|
|
|
|
|
{
|
|
|
|
|
// Configure management feature to use EF Core.
|
2023-06-06 18:49:14 +00:00
|
|
|
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore());
|
2023-03-24 10:11:27 +00:00
|
|
|
|
|
|
|
|
elsa.UseWorkflowRuntime(runtime =>
|
|
|
|
|
{
|
2023-06-28 18:55:57 +00:00
|
|
|
runtime.UseEntityFrameworkCore();
|
2023-03-24 10:11:27 +00:00
|
|
|
});
|
2022-12-30 12:11:29 +00:00
|
|
|
|
|
|
|
|
// Expose API endpoints.
|
|
|
|
|
elsa.UseWorkflowsApi();
|
|
|
|
|
|
|
|
|
|
// Add services for HTTP activities and workflow middleware.
|
|
|
|
|
elsa.UseHttp();
|
|
|
|
|
|
2023-01-27 23:36:03 +00:00
|
|
|
// Use timers.
|
|
|
|
|
elsa.UseScheduling();
|
|
|
|
|
|
2022-12-30 12:11:29 +00:00
|
|
|
// Configure identity so that we can create a default admin user.
|
|
|
|
|
elsa.UseIdentity(identity =>
|
|
|
|
|
{
|
2023-03-26 21:53:17 +00:00
|
|
|
identity.UseAdminUserProvider();
|
|
|
|
|
identity.TokenOptions = options =>
|
|
|
|
|
{
|
2024-01-17 21:11:03 +00:00
|
|
|
options.SigningKey = "super-secret-tamper-free-token-signing-key";
|
2023-03-26 21:53:17 +00:00
|
|
|
options.AccessTokenLifetime = TimeSpan.FromDays(1);
|
|
|
|
|
};
|
2022-12-30 12:11:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Use default authentication (JWT).
|
2023-04-22 10:25:06 +00:00
|
|
|
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
|
2023-01-27 23:36:03 +00:00
|
|
|
|
|
|
|
|
// Register custom activities.
|
2023-04-28 20:41:18 +00:00
|
|
|
elsa.AddActivitiesFrom<Program>();
|
2024-06-03 06:38:18 +00:00
|
|
|
|
|
|
|
|
// Register custom workflows.
|
|
|
|
|
elsa.AddWorkflowsFrom<Program>();
|
2022-12-30 12:11:29 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Configure CORS to allow designer app hosted on a different origin to invoke the APIs.
|
2023-12-10 11:15:03 +00:00
|
|
|
builder.Services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyOrigin().AllowAnyHeader().AllowAnyMethod().WithExposedHeaders("*")));
|
2022-12-30 12:11:29 +00:00
|
|
|
|
|
|
|
|
var app = builder.Build();
|
|
|
|
|
|
|
|
|
|
// Configure the HTTP request pipeline.
|
|
|
|
|
app.UseHttpsRedirection();
|
|
|
|
|
app.UseCors();
|
|
|
|
|
app.UseAuthentication();
|
|
|
|
|
app.UseAuthorization();
|
|
|
|
|
app.UseWorkflowsApi();
|
|
|
|
|
app.UseWorkflows();
|
|
|
|
|
app.Run();
|