Created
November 2, 2019 09:10
-
-
Save sfmskywalker/ff63612a1979f154297c9a277b049fd6 to your computer and use it in GitHub Desktop.
Startup.cs - Building Workflow Driven .NET Core Applications with Elsa
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Elsa.Activities.Email.Extensions; | |
using Elsa.Activities.Http.Extensions; | |
using Elsa.Activities.Timers.Extensions; | |
using Elsa.Dashboard.Extensions; | |
using Elsa.Extensions; | |
using Elsa.Persistence.MongoDb.Extensions; | |
using Elsa.Samples.UserRegistration.Web.Extensions; | |
using Elsa.Samples.UserRegistration.Web.Handlers; | |
using Elsa.Samples.UserRegistration.Web.Models; | |
using Elsa.Samples.UserRegistration.Web.Services; | |
using Fluid; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
namespace Elsa.Samples.UserRegistration.Web | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
private IConfiguration Configuration { get; } | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddRazorPages(); | |
services.AddServerSideBlazor(); | |
services | |
// Add Elsa services. | |
.AddElsa( | |
elsa => | |
{ | |
// Configure Elsa to use the MongoDB provider. | |
elsa.AddMongoDbStores(Configuration, databaseName: "UserRegistration", connectionStringName: "MongoDb"); | |
}) | |
// Add Elsa Dashboard services. | |
.AddElsaDashboard() | |
// Add the activities we want to use. | |
.AddEmailActivities(options => options.Bind(Configuration.GetSection("Elsa:Smtp"))) | |
.AddHttpActivities(options => options.Bind(Configuration.GetSection("Elsa:Http"))) | |
.AddTimerActivities(options => options.Bind(Configuration.GetSection("Elsa:Timers"))) | |
.AddUserActivities() | |
// Add our PasswordHasher service. | |
.AddSingleton<IPasswordHasher, PasswordHasher>() | |
// Add a MongoDB collection for our User model. | |
.AddMongoDbCollection<User>("Users") | |
// Add our liquid handler. | |
.AddNotificationHandlers(typeof(LiquidConfigurationHandler)); | |
} | |
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ | |
app.UseExceptionHandler("/Error"); | |
app.UseHsts(); | |
} | |
app.UseStaticFiles(); | |
// Add Elsa's middleware to handle HTTP requests to workflows. | |
app.UseHttpActivities(); | |
app.UseRouting(); | |
app.UseEndpoints( | |
endpoints => | |
{ | |
// Blazor stuff. | |
endpoints.MapBlazorHub(); | |
endpoints.MapFallbackToPage("/_Host"); | |
// Attribute-based routing stuff. | |
endpoints.MapControllers(); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment