My views extend a base view class ive made:
public class BaseView : ViewPage
At the moment im calling ObjectFactory.GetInstance inside this class' constructor to get some interface implementations but id like to use structuremap to inject them as constructor arguments.
Im using a structuremapcontrollerfactory to create my controllers, but how can i do the same for views?
I know i can implement a custom ViewEngine, but using reflector to look at the mvc default viewengine and its dependencies, it seems to go on and on and i'd rather not have to re-implement stuff thats already there. Has anyone got a cunning idea how to solve this?
I know i could make things easier with setter instead of constructor injection but id rather avoid that if possible.
-
Yes, if you are talking about the WebForms ViewEngine, you are correct in your assessment that it was not designed with inversion of control in mind. You can either lobby Microsoft to change it, or you can use setter injection. In FubuMVC, we use setter injection along with StructureMap's BuildUp method:
- WebFormsControlBuilder creates the instance of the view
- StructureMapWebFormsControlBuilder derives from WebFormsControlBuilder - calls the base to create the instance, and then calls BuildUp to perform setter injection on all applicable properites.
Andrew Bullock : setter injection it is
0 comments:
Post a Comment