Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are modules in nancyfx really created on each request?

Tags:

nancy

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?

like image 709
Stig Schmidt Nielsson Avatar asked Nov 28 '14 06:11

Stig Schmidt Nielsson


1 Answers

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.

like image 186
Steven Robbins Avatar answered Sep 28 '22 09:09

Steven Robbins