views:

290

answers:

1

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.

+1  A: 

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:

Joshua Flanagan
setter injection it is
Andrew Bullock