using Caspian.WorkflowFramework.Contracts; using Caspian.WorkflowFramework.Services; using Elsa.Extensions; using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Elsa.EntityFrameworkCore.Extensions; using Elsa.EntityFrameworkCore.Modules.Management; using Elsa.EntityFrameworkCore.Modules.Runtime; using Elsa.EntityFrameworkCore.Modules.Identity; using Elsa.Email; using MongoLogger; using MongoLogger.Models; namespace Caspian.WorkflowFramework; public static class DependencyInjectionq { public static void AddWorkflowFramework(this IHostApplicationBuilder builder, string connectionString) { builder.Services.AddMongoLogger(builder.Configuration); builder.Services.AddElsa(elsa => { // Configure Management layer to use EF Core. elsa.UseWorkflowManagement(management => management .UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString))); // Configure Runtime layer to use EF Core. elsa.UseWorkflowRuntime(runtime => runtime .UseEntityFrameworkCore(ef => ef.UseSqlServer(connectionString))); // Expose Elsa API endpoints. elsa.UseWorkflowsApi(); // Enable C# workflow expressions elsa.UseCSharp(); // Enable JavaScript workflow expressions elsa.UseJavaScript(options => options.AllowClrAccess = true); }); //// Configure CORS to allow designer app hosted on a different origin to invoke the APIs. //builder.Services.AddCors(cors => cors // .AddDefaultPolicy(policy => policy // .AllowAnyOrigin() // For demo purposes only. Use a specific origin instead. // .AllowAnyHeader() // .AllowAnyMethod() // .WithExposedHeaders("x-elsa-workflow-instance-id"))); // Required for Elsa Studio in order to support running workflows from the designer. Alternatively, you can use the `*` wildcard to expose all headers. // Add Health Checks. builder.Services.AddHealthChecks(); builder.Services.AddScoped(); } public static void UseWorkflowFramework(this IApplicationBuilder app) { try { app.UseMongoLogger(); } catch (Exception ex) { var d = ex; } //app.UseWorkflowsApi(); // Use Elsa API endpoints. app.UseWorkflows(); // Use Elsa middleware to handle HTTP requests mapped to HTTP Endpoint activities. } }