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.
This commit is contained in:
tekh 2025-11-25 16:33:18 +01:00
parent 7214b09640
commit a6cb0081ee

View File

@ -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<ConfigurationOptions> 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;
}
}