Closed KevinValmo closed 2 years ago
Due to the nature of minimal APIs all dependencies in a route delegate are resolved at runtime therefore modules cannot take any dependencies in their constructor as they will not be resolved when a route is hit. Carter modules could essentially be static classes with the routes defined in them. You could potentially inject singletons into a module but I don’t think I’d advise it just so it doesn’t get confusing
On Mon, 22 Nov 2021 at 23:15, Kevin Valmorbida @.***> wrote:
Hello.
This could be a discussion or a feature that could be added or not...
I was thinking about "old" Controllers and ControllerBases on the Mvc namespace. As the "old" Controllers are by default transient service (not always), don't you think to preserve this behaviur by adding to Services the ICarterModules as transient? Isn't it better to mark modules as transient lifetime services? Or it could be better maybe to let devs configure the lifetime of those ICarterModules service within an implementation of a ICarterModuleFactory or somethig else.
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/CarterCommunity/Carter/issues/288, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAAZVJR3K4ZCV6SFWW6HKLLUNLFHJANCNFSM5ISFUVBQ .
Hello.
This could be a discussion or a feature that could be added or not...
I was thinking about "old"
Controller
s andControllerBase
s on the Mvc namespace. As the "old"Controller
s are by default transient service (not always), don't you think to preserve this behaviur by adding toServices
theICarterModule
s as transient? Isn't it better to mark modules as transient lifetime services? Or it could be better maybe to let devs configure the lifetime of thoseICarterModule
s service within an implementation of aICarterModuleFactory
or somethig else.https://github.com/CarterCommunity/Carter/blob/5dc8a5e4d03ec91221d16b9faf41f7d1c9727f89/src/Carter/CarterExtensions.cs#L76-L79