elsa-core/src/samples/aspnet/Elsa.Samples.AspNet.WorkflowServer/Program.cs

57 lines
1.6 KiB
C#
Raw Normal View History

using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Extensions;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddElsa(elsa =>
{
// Configure management feature to use EF Core.
elsa.UseWorkflowManagement(management => management.UseEntityFrameworkCore());
elsa.UseWorkflowRuntime(runtime =>
{
runtime.UseEntityFrameworkCore();
});
// Expose API endpoints.
elsa.UseWorkflowsApi();
// Add services for HTTP activities and workflow middleware.
elsa.UseHttp();
// Use timers.
elsa.UseScheduling();
// Configure identity so that we can create a default admin user.
elsa.UseIdentity(identity =>
{
identity.UseAdminUserProvider();
identity.TokenOptions = options =>
{
options.SigningKey = "secret-token-signing-key";
options.AccessTokenLifetime = TimeSpan.FromDays(1);
};
});
// Use default authentication (JWT).
elsa.UseDefaultAuthentication(auth => auth.UseAdminApiKey());
// Register custom activities.
2023-04-28 20:41:18 +00:00
elsa.AddActivitiesFrom<Program>();
});
// 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("*")));
var app = builder.Build();
// Configure the HTTP request pipeline.
app.UseHttpsRedirection();
app.UseCors();
app.UseAuthentication();
app.UseAuthorization();
app.UseWorkflowsApi();
app.UseWorkflows();
app.Run();