开发者

ALL of my injected controllers' constructors are hit 4 times for each request

开发者 https://www.devze.com 2023-01-11 04:09 出处:网络
I\'m using MVCTurbine in my application which automatically injects my controllers in my asp.net-mvc 2.0 website. My master pages, view pages, css, web.configs and javascript files are in my mvc proje

I'm using MVCTurbine in my application which automatically injects my controllers in my asp.net-mvc 2.0 website. My master pages, view pages, css, web.configs and javascript files are in my mvc project, all the rest (including the global.asax) are in seperate libraries.

When I put a breakpoint at my Controller's constructors I notice that ALL the constructors are hit 4 times for each request and the controller with the actual action in gets hit an extra 5th time.

I've tried to reduce the problem surface in the following ways:

  • Reduced my view and masterpage to minimum (all custom code removed)
  • Reduced my view
  • Simplified my controller to the minimum
  • Simplified my global.asax.cs to minimum

The breakpoint has no meaningfull stacktrace.

Posted the simplified code to http://gist.github.com/514442

The problem code in context of a projec开发者_Go百科t can be found at http://github.com/boriscallens/Beek

I'm kind of out of ideas, any hints or ideas on how to continue debugging this are welcome.


I never noticed this before :/ Anyway, after some digging, I found where it calls the constructor 4 times. It's supposed to call them 4 times only once, and cache the results (it's looking for filters), but MvcTurbine seems to be losing the instance with the cache.

This is the class that's causing problems: http://github.com/lozanotek/mvcturbine/blob/master/src/Engine/MvcTurbine.Web/Controllers/DefaultFilterFinder.cs

If you copy & paste this class into your project, and register it in one of your IServiceRegistration classes it works like it's supposed to.

locator.Register<IFilterFinder, FilterFinder>();

(I renamed the class to FilterFinder from DefaultFilterFinder)

UPDATE

I figured out why it doesn't work. It's because when I downloaded the 2.1 version from downloads, the code that caches the results is not there yet. If you download the latest source from http://github.com/lozanotek/mvcturbine, it works (you have to compile the code, not use the binaries in deploy folder).

0

精彩评论

暂无评论...
验证码 换一张
取 消