feat(DependencyInjection): Add MediatR and configure dependency injection
This commit is contained in:
parent
78021a95a4
commit
409e43460d
35
src/DigitalData.ActiveDirectory/DependencyInjection.cs
Normal file
35
src/DigitalData.ActiveDirectory/DependencyInjection.cs
Normal file
@ -0,0 +1,35 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace DigitalData.ActiveDirectory;
|
||||
|
||||
public static class DependencyInjection
|
||||
{
|
||||
public static IServiceCollection AddActiveDirectory(this IServiceCollection services, Action<ADConfigurationOptions>? options = null)
|
||||
{
|
||||
var cOptions = new ADConfigurationOptions();
|
||||
options?.Invoke(cOptions);
|
||||
|
||||
services.AddMediatR(cfg =>
|
||||
{
|
||||
cfg.RegisterServicesFromAssemblies(typeof(DependencyInjection).Assembly);
|
||||
cfg.LicenseKey = cOptions.MediatRLicense;
|
||||
});
|
||||
|
||||
if (cOptions.Configuration is null)
|
||||
services.Configure<ActiveDirectoryOptions>(o => o = cOptions);
|
||||
else
|
||||
services.Configure<ActiveDirectoryOptions>(cOptions.Configuration);
|
||||
|
||||
return services;
|
||||
}
|
||||
|
||||
public class ADConfigurationOptions : ActiveDirectoryOptions
|
||||
{
|
||||
internal ADConfigurationOptions() { }
|
||||
|
||||
public string? MediatRLicense { get; set; }
|
||||
|
||||
public IConfiguration? Configuration { get; set; }
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="7.0.0" />
|
||||
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="7.0.1" />
|
||||
<PackageReference Include="MediatR" Version="13.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net7.0'">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user