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:
parent
7214b09640
commit
a6cb0081ee
32
src/ReC.Application/DependencyInjection.cs
Normal file
32
src/ReC.Application/DependencyInjection.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user