< Summary

Information
Class: Microsoft.Extensions.DependencyInjection.DependencyInjectionExtensions
Assembly: Elsa.Workflows.Runtime
File(s): /home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/DependencyInjectionExtensions.cs
Line coverage
72%
Covered lines: 13
Uncovered lines: 5
Coverable lines: 18
Total lines: 99
Line coverage: 72.2%
Branch coverage
50%
Covered branches: 2
Total branches: 4
Branch coverage: 50%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
AddGracefulShutdownOptions(...)100%22100%
AddWorkflowDefinitionProvider(...)100%210%
AddTriggerPayloadValidator(...)100%11100%
AddWorkflowsProvider(...)100%11100%
AddWorkflow(...)100%11100%
AddWorkflow(...)100%11100%
AddWorkflowsFrom(...)100%210%
AddWorkflowsFrom(...)0%620%
AddWorkflowRegistration(...)100%11100%

File(s)

/home/runner/work/elsa-core/elsa-core/src/modules/Elsa.Workflows.Runtime/Extensions/DependencyInjectionExtensions.cs

#LineLine coverage
 1using System.Diagnostics.CodeAnalysis;
 2using System.Reflection;
 3using Elsa.Extensions;
 4using Elsa.Workflows;
 5using Elsa.Workflows.Options;
 6using Elsa.Workflows.Runtime;
 7using Elsa.Workflows.Runtime.Contracts;
 8using Elsa.Workflows.Runtime.Discovery;
 9using Elsa.Workflows.Runtime.Options;
 10using Elsa.Workflows.Runtime.Providers;
 11using Microsoft.Extensions.DependencyInjection.Extensions;
 12using Microsoft.Extensions.Options;
 13using Elsa.Common.Serialization;
 14
 15// ReSharper disable once CheckNamespace
 16namespace Microsoft.Extensions.DependencyInjection;
 17
 18/// <summary>
 19/// Provides extension methods for <see cref="IServiceCollection"/>.
 20/// </summary>
 21public static class DependencyInjectionExtensions
 22{
 23    /// <summary>
 24    /// Registers and validates <see cref="GracefulShutdownOptions"/>.
 25    /// </summary>
 26    public static IServiceCollection AddGracefulShutdownOptions(this IServiceCollection services, Action<GracefulShutdow
 27    {
 22928        var builder = services.AddOptions<GracefulShutdownOptions>().ValidateOnStart();
 22929        services.TryAddEnumerable(ServiceDescriptor.Singleton<IValidateOptions<GracefulShutdownOptions>, Elsa.Extensions
 30
 22931        if (configure != null)
 1432            builder.Configure(configure);
 33
 34
 22935        return services;
 36    }
 37
 38    /// <summary>
 39    /// Adds the specified workflow provider type to the service collection.
 40    /// </summary>
 41    /// <typeparam name="T">The type of the workflow provider to add. Must implement <see cref="IWorkflowsProvider"/>.</
 42    [Obsolete("Use AddWorkflowsProvider instead.", false)]
 043    public static IServiceCollection AddWorkflowDefinitionProvider<T>(this IServiceCollection services) where T : class,
 44    /// <summary>
 45    /// Registers a <see cref="ITriggerPayloadValidator{TPayload}"/> with the service container.
 46    /// </summary>
 47    /// <param name="services">Service collection</param>
 48    /// <typeparam name="TValidator">Validator of the validator</typeparam>
 49    /// <typeparam name="TPayload">Payload type</typeparam>
 50    public static IServiceCollection AddTriggerPayloadValidator<TValidator, TPayload>(this IServiceCollection services)
 51        where TValidator : class, ITriggerPayloadValidator<TPayload>
 52    {
 22253        return services.AddScoped<ITriggerPayloadValidator<TPayload>, TValidator>();
 54    }
 55
 56    /// <summary>
 57    /// Adds the specified workflows provider type to the service collection.
 58    /// </summary>
 59    /// <typeparam name="T">The type of the workflows provider to add. Must implement <see cref="IWorkflowsProvider"/>.<
 23960    public static IServiceCollection AddWorkflowsProvider<T>(this IServiceCollection services) where T : class, IWorkflo
 61
 62    /// <summary>
 63    /// Registers the specified code-first workflow type.
 64    /// </summary>
 165    public static IServiceCollection AddWorkflow<T>(this IServiceCollection services) where T : IWorkflow => services.Ad
 66
 67    /// <summary>
 68    /// Registers the specified code-first workflow type.
 69    /// </summary>
 70    public static IServiceCollection AddWorkflow(this IServiceCollection services, Type workflowType)
 71    {
 172        AddWorkflowRegistration(services, workflowType);
 173        return services;
 74    }
 75
 76    /// <summary>
 77    /// Registers all code-first workflows contained in the assembly containing the specified marker type.
 78    /// </summary>
 79    [RequiresUnreferencedCode("The assembly is required to be referenced.")]
 080    public static IServiceCollection AddWorkflowsFrom<TMarker>(this IServiceCollection services) => services.AddWorkflow
 81
 82    /// <summary>
 83    /// Registers all code-first workflows in the specified assembly.
 84    /// </summary>
 85    [RequiresUnreferencedCode("The assembly is required to be referenced.")]
 86    public static IServiceCollection AddWorkflowsFrom(this IServiceCollection services, Assembly assembly)
 87    {
 088        foreach (var workflowType in WorkflowTypeScanner.GetWorkflowTypes(assembly))
 089            AddWorkflowRegistration(services, workflowType);
 90
 091        return services;
 92    }
 93
 94    private static void AddWorkflowRegistration(IServiceCollection services, Type workflowType)
 95    {
 296        services.PostConfigure<RuntimeOptions>(options => options.Workflows.Add(workflowType));
 197        services.Configure<SerializationTypeOptions>(options => options.AddSimpleAssemblyQualifiedTypeAlias(workflowType
 198    }
 99}