feat(DirectorySearchQuery): integrate auto-mapper.
- configure automapper
This commit is contained in:
parent
b69867468d
commit
168dff5f60
@ -16,6 +16,14 @@ public static class DependencyInjection
|
||||
cfg.LicenseKey = cOptions.MediatRLicenseKey;
|
||||
});
|
||||
|
||||
services.AddAutoMapper(cfg =>
|
||||
{
|
||||
#if NET8_0_OR_GREATER
|
||||
cfg.LicenseKey = cOptions.MediatRLicenseKey;
|
||||
#endif
|
||||
cfg.AddMaps(typeof(DependencyInjection).Assembly);
|
||||
});
|
||||
|
||||
if (!cOptions.IsADConfigured)
|
||||
services.Configure<ActiveDirectoryOptions>(_ => { });
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="8.0.0" />
|
||||
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="8.0.1" />
|
||||
<PackageReference Include="MediatR" Version="13.0.0" />
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="8.0.0" />
|
||||
</ItemGroup>
|
||||
@ -38,7 +38,7 @@
|
||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="9.0.7" />
|
||||
<PackageReference Include="System.DirectoryServices.AccountManagement" Version="9.0.7" />
|
||||
<PackageReference Include="MediatR" Version="13.0.0" />
|
||||
<PackageReference Include="AutoMapper" Version="14.0.0" />
|
||||
<PackageReference Include="AutoMapper" Version="15.0.1" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Caching.Abstractions" Version="9.0.5" />
|
||||
</ItemGroup>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using DigitalData.Core.Exceptions;
|
||||
using AutoMapper;
|
||||
using DigitalData.Core.Exceptions;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System.DirectoryServices;
|
||||
@ -16,9 +17,12 @@ public class DirectorySearchQueryHandler : IRequestHandler<DirectorySearchQuery,
|
||||
{
|
||||
private readonly IOptions<ActiveDirectoryOptions> _options;
|
||||
|
||||
public DirectorySearchQueryHandler(IOptions<ActiveDirectoryOptions> options)
|
||||
private readonly IMapper _mapper;
|
||||
|
||||
public DirectorySearchQueryHandler(IOptions<ActiveDirectoryOptions> options, IMapper mapper)
|
||||
{
|
||||
_options = options;
|
||||
_mapper = mapper;
|
||||
}
|
||||
|
||||
public DirectoryEntry DirectoryEntry => new ()
|
||||
@ -32,14 +36,9 @@ public class DirectorySearchQueryHandler : IRequestHandler<DirectorySearchQuery,
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
using var _dirEntry = DirectoryEntry;
|
||||
using var searcher = new DirectorySearcher()
|
||||
{
|
||||
Filter = request.Filter,
|
||||
SearchScope = request.Scope,
|
||||
SizeLimit = request.SizeLimit,
|
||||
SearchRoot = _dirEntry
|
||||
};
|
||||
using var searcher = _mapper.Map<DirectorySearcher>(request);
|
||||
|
||||
searcher.SearchRoot = DirectoryEntry;
|
||||
|
||||
request.AfterInit?.Invoke(searcher);
|
||||
|
||||
|
||||
13
src/DigitalData.ActiveDirectory/MappingProfile.cs
Normal file
13
src/DigitalData.ActiveDirectory/MappingProfile.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using AutoMapper;
|
||||
using System.DirectoryServices;
|
||||
|
||||
namespace DigitalData.ActiveDirectory;
|
||||
|
||||
public class MappingProfile : Profile
|
||||
{
|
||||
[System.Diagnostics.CodeAnalysis.SuppressMessage("Interoperability", "CA1416:Validate platform compatibility", Justification = "<Pending>")]
|
||||
public MappingProfile()
|
||||
{
|
||||
CreateMap<DirectorySearchQuery, DirectorySearcher>();
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user