From 1b21ccecf3777f5f5c7f67a18211282821f89b7b Mon Sep 17 00:00:00 2001 From: Developer 02 Date: Wed, 23 Oct 2024 17:42:19 +0200 Subject: [PATCH] feat(DIExtensions): Methoden zur Injektion von Workflow-Diensten und mit TryAddScoped-Methode erstellt. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Umwandlung von AddScoped in TryAddScoped in der Methode AddWorkFlowRepositories. - Methode mit dem Namen AddWorkFlow erstellt, um Dienste und Repositories zusammen hinzuzufügen --- WorkFlow.Application/DIExtensions.cs | 25 +++++++++++++++++++++++++ WorkFlow.Infrastructure/DIExtensions.cs | 17 +++++++++++------ 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 WorkFlow.Application/DIExtensions.cs diff --git a/WorkFlow.Application/DIExtensions.cs b/WorkFlow.Application/DIExtensions.cs new file mode 100644 index 0000000..4f48499 --- /dev/null +++ b/WorkFlow.Application/DIExtensions.cs @@ -0,0 +1,25 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; +using WorkFlow.Application.Contracts; +using WorkFlow.Application.Services; +using WorkFlow.Infrastructure; + +namespace WorkFlow.Application +{ + public static class DIExtensions + { + public static IServiceCollection AddWorkFlowServices(this IServiceCollection services) + { + services.AddAutoMapper(typeof(MappingProfile).Assembly); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + + return services; + } + + public static IServiceCollection AddWorkFlow(this IServiceCollection services) => services.AddWorkFlowRepositories().AddWorkFlowServices(); + } +} \ No newline at end of file diff --git a/WorkFlow.Infrastructure/DIExtensions.cs b/WorkFlow.Infrastructure/DIExtensions.cs index b938b07..a7b63d5 100644 --- a/WorkFlow.Infrastructure/DIExtensions.cs +++ b/WorkFlow.Infrastructure/DIExtensions.cs @@ -1,4 +1,5 @@ using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.DependencyInjection.Extensions; using WorkFlow.Infrastructure.Contracts; using WorkFlow.Infrastructure.Repositories; @@ -6,11 +7,15 @@ namespace WorkFlow.Infrastructure { public static class DIExtensions { - public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services) => services - .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped() - .AddScoped(); + public static IServiceCollection AddWorkFlowRepositories(this IServiceCollection services) + { + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + services.TryAddScoped(); + + return services; + } } } \ No newline at end of file