Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Mar 07, 2012 06:18 AM by priya_marwaha
Mar 07, 2012 05:09 AM|LINK
I need to initialize some data that will be static for all instances of my particular controller. Once its initialized, I basically add this data as a custom property on the controller's descriptor by overriding the Initialize method. My question is....apart
from doing the initialization in a static constructor of the controller, is there any other (or better) way of doing this? The nature of the data is such that it will not change until I actually change the class definition (basically, its related to a bunch
of class and method level attributes).
Mar 07, 2012 05:57 AM|LINK
A static constructor sounds fine in this case.
Mar 07, 2012 06:18 AM|LINK
Thanks....but it kinda gets complicated if this controller is a base controller...in which case, I can't access the child class related attributes :( I was trying to analyze the WebAPI pipeline, but it looks like controller factory etc. are all called per
request (i.e. IHttpControllerFactory.CreateController etc.). Short of adding static data via HttpRoute data tokens, I'm not sure where else I can place the data in order to avoid computation per request.
Guess I'm looking for the equivalent of something like the WCF behavior's ApplyDispatchBehavior method!
[Edit] For now, I've decided to stick with adding the data as part of the Http route's data token dictionary. Since the data is related to some custom attributes on the controller's class, its easy enough to compute this once when setting up the route.