-
-
Notifications
You must be signed in to change notification settings - Fork 7
Description
Created from #28 .
By default, ServiceScan scans types in the assembly, where attributed method is located. It's possible to set assembly to scan explicitly via FromAssemblyOf attribute parameter.
In some cases it might be beneficial to scan not one, but multiple assemblies:
I am implementing module monolith, each module is declared in saperate project and maps its endpoints and adds services with static abstract method.
Currenly it is possible to add multiple assemblies by adding multiple attributes, like:
public static partial class ServiceCollectionExtensions
{
[GenerateServiceRegistrations(AssignableTo = typeof(IEndpoint), FromAssemblyOf = typeof(FirstType), CustomHandler = nameof(MapEndpoint))]
[GenerateServiceRegistrations(AssignableTo = typeof(IEndpoint), FromAssemblyOf = typeof(SecondType), CustomHandler = nameof(MapEndpoint))]
public static partial IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder endpoints);
private static void MapEndpoint<T>(IEndpointRouteBuilder endpoints) where T : IEndpoint
{
T.MapEndpoint(endpoints);
}
}Does it make sence to allow setting multiple assemblies in the same attribute to make it shorter?
E.g.
public static partial class ServiceCollectionExtensions
{
[GenerateServiceRegistrations(AssignableTo = typeof(IEndpoint), FromAssemblyOf = [typeof(FirstType), typeof(SecondType)], CustomHandler = nameof(MapEndpoint))]
public static partial IEndpointRouteBuilder MapEndpoints(this IEndpointRouteBuilder endpoints);
private static void MapEndpoint<T>(IEndpointRouteBuilder endpoints) where T : IEndpoint
{
T.MapEndpoint(endpoints);
}
}While it is a bit shorter, I'm a bit hesitant to add new filter properties, I don't want to end up with tens of properties, which are hard to maintain and are confusing to end users (e.g. does it make sense to add array counterpart for AssignableTo or AttributeFilter properties?).