A library to help simplify type and assembly discovery.
$ dotnet add package AsyncHandler.AssemblyAsyncHandler.Assembly helps simplifying type discovery overhead when searching through .Net assemblies with a bunch of helpful methods to speed up your development.
The library runs on the stable release of .Net 8 and requires the SDK installed:
https://dotnet.microsoft.com/en-us/download/dotnet/8.0
Iinstall AsyncHandler.Assembly package.
dotnet add package AsyncHandler.Assembly
Search for a derived type by its root.
using System.Reflection;
using AsyncHandler.Assembly;
public record AggregateRoot;
public record OrderAggregate : AggregateRoot;
var assembly = Assembly.GetExecutingAssembly();
var type = TDiscover.FindByAsse<AggregateRoot>(assembly);
// or typeof(AggregateRoot).FindByAsse(assembly);
Use FindByCallingAsse() to start from calling assembly all the way back to matching assembly, FindByCallingAsse() offers significant performance gains.
typeof(AggregateRoot).FindByCallingAsse(Assembly.GetCallingAssembly());
Search for a type through AppDomain, smart tricks and filters are applied to enhance the search.
public record DomainEvent;
public record OrderPlaced : DomainEvent;
TDiscover.FindByType<DomainEvent>();
To further enhance the above search, use FindByTypeName to specify the type and name as well.
public record DomainEvent;
public record OrderPlaced : DomainEvent;
public record OrderConfirmed : DomainEvent;
TDiscover.FindByTypeName<DomainEvent>("OrderPlaced");
// or typeof(DomainEvent).FindByTypeName("OrderPlaced");
Search for a type when all you have is the type name.
TDiscover.FindByTypeName("OrderPlaced");
If you are an event sourcer and love OSS, give AsyncHandler.Assembly a star. :purple_heart:
This project is licensed under the terms of the MIT license.