Carter module and dependency injection
dmantovani73 opened this issue · comments
Hi,
a Carter module can register routes but how can (a Carter module) inject dependencies in the DI container?
Thanks.
It can't, as of .NET6 dependencies are injected into the route handler directly not into the module constructor. You could technically inject singleton registrations into the constructor but I would recommend you follow the minimal api .NET6 recommendations.
See how this is injected into the route handler and registered in Program.cs https://github.com/CarterCommunity/Carter/blob/main/samples/CarterSample/Features/Actors/ActorsModule.cs#L12
Thank you.