Created
October 28, 2021 07:36
-
-
Save Zabaa/d06c7523ff0f3aac1f2c5c0fd2eda8a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[HttpGet("GetAllCommandHandlers")] | |
public async Task<IEnumerable<string>> GetAllCommandHandlers() | |
{ | |
var genericType = typeof(ICommandHandler<>); | |
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) | |
.Where(t => t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(genericType))) | |
.Select(x => $"{x.FullName}.{x.Name}").ToList(); | |
var genericTypeWithResult = typeof(ICommandHandler<,>); | |
var typesWithresult = AppDomain.CurrentDomain.GetAssemblies().SelectMany(x => x.GetTypes()) | |
.Where(t => t.GetInterfaces().Any(i => i.IsGenericType && i.GetGenericTypeDefinition().Equals(genericTypeWithResult))) | |
.Select(x => $"{x.Module}.{x.Name}").ToList(); | |
types.Add("With result: "); | |
types.AddRange(typesWithresult); | |
return await Task.FromResult(types); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment