-
-
Notifications
You must be signed in to change notification settings - Fork 195
Description
Hi,
Being accustomed to controllers I installed Carter and ran into an issue similar to these when injecting a scoped service into a module's constructor threw an exception:
- Registering modules as Singleton is causing problems #279
- ICarterModule as Singleton services? #288
.
And I also think that this unknowingly affects many people who inject transient services (ie MediatR library) into a module's constructor.
It appears to me that with an interface like this:
public interface ICarterModuleV2 // Naming things is hard.
{
static abstract void AddRoutes(IEndpointRouteBuilder app);
}this could be completely avoided and AddRoutes could still be called through reflection (easy, less efficient) or a source generator (hard, as efficient as hard-coded by a dev).
What do you think? Would this be a worthwhile addition?
EDIT: Turns out there's even a tutorial for this exact source generator: https://dev.to/joaofbantunes/mapping-aspnet-core-minimal-api-endpoints-with-c-source-generators-3faj.