Skip to content

Instantly share code, notes, and snippets.

@Zabaa
Created October 28, 2021 07:36
Show Gist options
  • Save Zabaa/d06c7523ff0f3aac1f2c5c0fd2eda8a2 to your computer and use it in GitHub Desktop.
Save Zabaa/d06c7523ff0f3aac1f2c5c0fd2eda8a2 to your computer and use it in GitHub Desktop.
[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