From a6cb0081eea76797ce08cb7337253ac01ded0f94 Mon Sep 17 00:00:00 2001 From: TekH Date: Tue, 25 Nov 2025 16:33:18 +0100 Subject: [PATCH] Add DependencyInjection class for service registration Introduced a new `DependencyInjection` class in the `ReC.Application` namespace to streamline service registration. - Added `AddRecServices` extension method for `IServiceCollection` to configure AutoMapper and MediatR with assembly scanning. - Included `ConfigurationOptions` class to allow configuration of a `LuckyPennySoftwareLicenseKey`. - Added `using` directives for `Microsoft.Extensions.DependencyInjection` and `System.Reflection` to support dependency injection and assembly scanning. --- src/ReC.Application/DependencyInjection.cs | 32 ++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/ReC.Application/DependencyInjection.cs diff --git a/src/ReC.Application/DependencyInjection.cs b/src/ReC.Application/DependencyInjection.cs new file mode 100644 index 0000000..68a3e35 --- /dev/null +++ b/src/ReC.Application/DependencyInjection.cs @@ -0,0 +1,32 @@ +using Microsoft.Extensions.DependencyInjection; +using System.Reflection; + +namespace ReC.Application; + +public static class DependencyInjection +{ + public static IServiceCollection AddRecServices(this IServiceCollection services, Action options) + { + var configOpt = new ConfigurationOptions(); + options.Invoke(configOpt); + + services.AddAutoMapper(cfg => + { + cfg.AddMaps(Assembly.GetExecutingAssembly()); + cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey; + }); + + services.AddMediatR(cfg => + { + cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()); + cfg.LicenseKey = configOpt.LuckyPennySoftwareLicenseKey; + }); + + return services; + } + + public class ConfigurationOptions + { + public string LuckyPennySoftwareLicenseKey { get; set; } = string.Empty; + } +}