refactor(DirectorySearchQuery): Root-Datensatz definieren.

- SearchRoot-Eigenschaft hinzufügen
 - Zuordnungsprofil zwischen DirectorySearchQuery.Root und DirectoryEntry hinzufügen
 - Logik hinzufügen, um den Standardwert SearcdhRoot zu verwenden, wenn DirectorySearchQuery.Root null ist
This commit is contained in:
Developer 02 2025-08-05 15:41:01 +02:00
parent d0de978c7d
commit f73730ba65
2 changed files with 11 additions and 8 deletions

View File

@ -9,6 +9,10 @@ namespace DigitalData.ActiveDirectory;
public record DirectorySearchQuery(string? Filter = null, SearchScope Scope = SearchScope.Subtree, int SizeLimit = 5000, params string[] Property)
: IRequest<IEnumerable<ResultPropertyCollection>>
{
public record Root(string Path, string? Username = null, string? Password = null);
public Root? SearchRoot { get; set; }
public Action<DirectorySearcher>? AfterInit { get; set; }
}
@ -25,13 +29,6 @@ public class DirectorySearchQueryHandler : IRequestHandler<DirectorySearchQuery,
_mapper = mapper;
}
public DirectoryEntry DirectoryEntry => new ()
{
Path = _options.Value.Path,
Username = _options.Value.Username,
Password = _options.Value.Password
};
//TODO: add resolver to handle SearchRoot and AfterInit mapping
public Task<IEnumerable<ResultPropertyCollection>> Handle(DirectorySearchQuery request, CancellationToken cancellationToken = default)
{
@ -39,7 +36,12 @@ public class DirectorySearchQueryHandler : IRequestHandler<DirectorySearchQuery,
{
using var searcher = _mapper.Map<DirectorySearcher>(request);
searcher.SearchRoot = DirectoryEntry;
searcher.SearchRoot ??= new()
{
Path = _options.Value.Path,
Username = _options.Value.Username,
Password = _options.Value.Password
};
request.AfterInit?.Invoke(searcher);

View File

@ -9,5 +9,6 @@ public class MappingProfile : Profile
public MappingProfile()
{
CreateMap<DirectorySearchQuery, DirectorySearcher>();
CreateMap<DirectorySearchQuery.Root, DirectoryEntry>();
}
}