CarterCommunity / Carter

Carter is framework that is a thin layer of extension methods and functionality over ASP.NET Core allowing code to be more explicit and most importantly more enjoyable.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.