views:

58

answers:

4

With ASP.NET MVC it is pretty easy to integrate an IoC container to create the controllers.

Is the same thing also possible with webforms to create the pages and controls and pass them any dependencies? If yes, where do I have to plug it in?

+2  A: 

Yes you can, here's an example of how Spring.NET does it.

Darin Dimitrov
+2  A: 

Castle Windsor was the first major IoC container for ASP.NET. See this question discussing how it can be used with Web forms.

kgiannakakis
+1  A: 

Not directly, as Web Forms does not allow any code to take control of Page and Control instantiation. So something like a Page Factory is not feasible, and you can't do constructor injection.

But there are work arounds/hacks that can buy you setter injection as others have mentioned.

Mauricio Scheffer
A: 

Another good approach would be using the Model-View-Presenter pattern and have your dependencies injected into the presenter's constructor.

Fernando