I have created a simple self hosted Nancy site with a single module in a console project. When testing it out I noticed that the module constructor is called on each request. This puzzles me because the ctor is also where routes are registered. That does not make sense to me and I must be missing something. So are module constructors called on each request and are all routes thus re-registered on each request?
Sort of - Nancy will construct all modules at startup, register all their routes and build the routing Tree. For each request it will then figure out which Module it needs and construct it using the request container, so request scoped dependencies have the correct lifetime, then executes the relevant action. The routes are not "registered" every request, they are just stored in a collection in the module and the engine executes the correct one.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With