Injection => functions are called extra times

Topics: General
Jul 15, 2011 at 7:48 AM


I understand why using injection with Orchard (I'm new with this concept of Inversion of Control) and I find it pretty helpful.

Nevertheless, I don't know if that can't work differently or if it was made on purpose but I find strange that the functions BuildManifests in the ResourceManifest.cs files are called every time a new page is accessed in the dashboard (probably true on the website too). Can the scripts and style sheets not be declared only when the modules which declare them are being enabled?


Jul 15, 2011 at 1:21 PM

There's no reason to single out ResourceManifest; a large amount of injected code gets executed for every page request. This is typical of all websites, generally you run loads of code for each request. ResourceManifests are pretty lightweight; where code is taking a long time to run, caching can be utilised to improve performance. But if you cached absolutely everything, you'd start getting a lot of memory problems.

Jul 15, 2011 at 6:49 PM

Not only that: it so happens that this particular implementation is relying on static resources, but there could be other implementations of the same interface that do everything dynamically, so we can't rely on this being stable. This means that if there is a need for caching, it should be done in the service, not around it.