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

115 lines
4.2 KiB
C#
Raw Normal View History

using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.Extensions;
2023-06-08 10:01:26 +00:00
using Elsa.Samples.AspNet.WorkflowContexts.Contracts;
using Elsa.Samples.AspNet.WorkflowContexts.Providers;
using Elsa.Samples.AspNet.WorkflowContexts.Services;
using Elsa.Samples.AspNet.WorkflowContexts.Workflows;
Add a more generic UIHandler to customize how inputAttributes can be handle by UI (#4688) * add a more generic UIHandler to customize how inputAttributes can be handle by the ui * Add IPropertyUIHandlerResolver and update PropertyUIHandlerResolver Introduced a new interface, IPropertyUIHandlerResolver, to resolve UI options for a property. Refactored PropertyUIHandlerResolver to implement this interface and removed the unnecessary partial class structure. Also, cleaned up some unnecessary usings in various files for better code organization. * Refactor variable name and description in InputDescriptor The 'uISpecifications' variable in the InputDescriptor model is renamed to 'uiSpecifications' for better readability. Additionally, the associated comment was revised to explain that the dictionary is used by the UI. * "Refactor codebase for improved organization and cleaner architecture" The codebase has been significantly refactored, moving several classes to more appropriate namespaces for improved organization and cleaner architecture. This includes shifting UI hint handlers, activities, and memory-related components, amongst others. The changes should improve code readability and maintainability, but as this is a broad refactoring effort, thorough regression testing is advised. * Add CheckList UIHint with associated handler and provider This update introduces a new UIHint called CheckList to the Elsa.Workflows.Core. This includes the necessary handler and provider classes. The handler is registered in the WorkflowsFeature.cs, and the CheckList UIHint key has been added to the InputUIHints.cs. Various associated files have been created in both the Elsa.Api.Client and Elsa.Workflows.Core project to support this new UIHint. --------- Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com> Co-authored-by: Sipke Schoorstra <sipkeschoorstra@outlook.com>
2023-12-26 17:56:29 +00:00
using Elsa.Workflows.Middleware.Activities;
using Elsa.Workflows.Middleware.Workflows;
var builder = WebApplication.CreateBuilder(args);
var services = builder.Services;
var configuration = builder.Configuration;
var sqliteConnectionString = configuration.GetConnectionString("Sqlite")!;
var identitySection = configuration.GetSection("Identity");
var identityTokenSection = identitySection.GetSection("Tokens");
// Add Elsa services.
services
.AddElsa(elsa => elsa
.AddActivitiesFrom<Program>()
.AddWorkflow<CustomerCommunicationsWorkflow>()
.UseIdentity(identity =>
{
identity.IdentityOptions = options => identitySection.Bind(options);
identity.TokenOptions = options => identityTokenSection.Bind(options);
identity.UseConfigurationBasedUserProvider(options => identitySection.Bind(options));
identity.UseConfigurationBasedApplicationProvider(options => identitySection.Bind(options));
identity.UseConfigurationBasedRoleProvider(options => identitySection.Bind(options));
})
.UseDefaultAuthentication()
.UseWorkflows(workflows =>
{
// Configure workflow execution pipeline to handle workflow contexts.
workflows.WithWorkflowExecutionPipeline(pipeline => pipeline
.Reset()
.UsePersistentVariables()
.UseBookmarkPersistence()
.UseWorkflowExecutionLogPersistence()
.UseWorkflowExecutionLogPersistence()
.UseActivityExecutionLogPersistence()
.UseWorkflowContexts()
.UseExceptionHandling()
.UseDefaultActivityScheduler()
);
// Configure activity execution pipeline to handle workflow contexts.
workflows.WithActivityExecutionPipeline(pipeline => pipeline
.Reset()
.UseExceptionHandling()
.UseExecutionLogging()
.UseWorkflowContexts()
.UseBackgroundActivityInvoker()
);
})
.UseWorkflowManagement(management =>
{
// Use EF core for workflow definitions and instances.
management.UseWorkflowInstances(m => m.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString)));
management.UseEntityFrameworkCore(m => m.UseSqlite(sqliteConnectionString));
})
.UseWorkflowRuntime(runtime =>
{
// Use EF core for triggers and bookmarks.
runtime.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
})
.UseWorkflowContexts()
.UseScheduling()
.UseWorkflowsApi(api => api.AddFastEndpointsAssembly<Program>())
.UseJavaScript()
.UseLiquid()
.UseHttp()
.UseEmail(email => email.ConfigureOptions = options => configuration.GetSection("Smtp").Bind(options))
);
// Add health checks.
services.AddHealthChecks();
// Add CORS.
services.AddCors(cors => cors.AddDefaultPolicy(policy => policy.AllowAnyHeader().AllowAnyMethod().AllowAnyOrigin()));
// Add domain services.
services.AddSingleton<ICustomerStore, MemoryCustomerStore>();
// Add workflow context providers.
services.AddWorkflowContextProvider<CustomerWorkflowContextProvider>();
services.AddWorkflowContextProvider<OrderWorkflowContextProvider>();
// Configure middleware pipeline.
var app = builder.Build();
if (app.Environment.IsDevelopment())
app.UseDeveloperExceptionPage();
// CORS.
app.UseCors();
// Health checks.
app.MapHealthChecks("/");
app.UseAuthentication();
app.UseAuthorization();
// Elsa API endpoints for designer.
app.UseWorkflowsApi();
// Captures unhandled exceptions and returns a JSON response.
app.UseJsonSerializationErrorHandler();
// Elsa HTTP Endpoint activities
app.UseWorkflows();
// Run.
app.Run();