-
Notifications
You must be signed in to change notification settings - Fork 1
Getting Started
Akash Kava edited this page Nov 10, 2021
·
10 revisions
public class WorkflowContext: EternityContext {
public WorkflowContext(IServiceProvider services):
base(new EternityAzureStorage(("ET", "azure storage connection string...")),
services, new EternityClock()) {
}
}
// register this as background service
public class WorkflowBackgroundService : BackgroundService {
private readonly WorkflowContext workflowContext;
private readonly TelemetryClient telemetryClient;
public WorkflowBackgroundService(WorkflowContext workflowContext, TelemetryClient telemetryClient)
{
this.workflowContext = workflowContext;
this.telemetryClient = telemetryClient;
}
protected async override Task ExecuteAsync(CancellationToken stoppingToken) {
while (!stoppingToken.IsCancellationRequested) {
try {
await workflowService.ProcessMessagesAsync(cancellationToken: stoppingToken);
} catch (Exception ex) {
telemetryClient.TrackException(ex);
}
}
}
}
To enable Microsoft.DependencyInjection.Extensions
Scope, add following in configure method.
services.AddEternityServiceScope();
This will make every activity execute in separate service scope, you can inject scoped services in Activities.
// create new workflow and execute now
var id = await SignupWorkflow.CreateAsync(context, "[email protected]");
// raise an event...
await context.RaiseEventAsync(id, SignupWorkflow.Verify, verificationCode);