using Microsoft.Extensions.DependencyInjection.Extensions; namespace DIT.Workflower.DependencyInjection.Extensions; public static class IServiceCollectionExtensions { public static ITransitionStart> AddWorkflowDefinition(this IServiceCollection services, in int version = 1) where TState : struct where TCommand : struct { var id = WorkflowDefinitionWrapper.GetDefaultId(); return AddWorkflowDefinition(services, id, version); } public static ITransitionStart> AddWorkflowDefinition(this IServiceCollection services, in string id) where TState : struct where TCommand : struct { return AddWorkflowDefinition(services, id, version: 1); } public static ITransitionStart> AddWorkflowDefinition(this IServiceCollection services, string id, int version) where TState : struct where TCommand : struct { var builder = WorkflowDefinitionBuilder>.Create(); services.TryAddSingleton>, DefaultWorkflowFactory>>(); services.AddSingleton>, WorkflowDefinitionWrapper>>(sp => { var definition = (WorkflowDefinitionBuilder>)builder; var wrapper = new WorkflowDefinitionWrapper>(definition, id, version); return wrapper; }); return builder; } }