Decoupling the view, presentation and ASP.NET Web Forms

Posted by John Leidegren on Stack Overflow See other posts from Stack Overflow or by John Leidegren
Published on 2010-04-05T14:03:37Z Indexed on 2010/04/05 14:13 UTC
Read the original article Hit count: 265

Filed under:
|
|
|
|

I have an ASP.NET Web Forms page which the presenter needs to populate with controls. This interaction is somewhat sensitive to the page-life cycle and I was wondering if there's a trick to it, that I don't know about.

I wanna be practical about the whole thing but not compromise testability.

Currently I have this:

public interface ISomeContract
{
    void InstantiateIn(System.Web.UI.Control container); 
}

This contract has a dependency on System.Web.UI.Control and I need that to be able to do things with the ASP.NET Web Forms programming model. But neither the view nor the presenter may have knowledge about ASP.NET server controls.

How do I get around this? How can I work with the ASP.NET Web Forms programming model in my concrete views without taking a System.Web.UI.Control dependency in my contract assemblies?

To clarify things a bit, this type of interface is all about UI composition (using MEF). It's known through-out the framework but it's really only called from within the concrete view. The concrete view is still the only thing that knows about ASP.NET Web Forms. However those public methods that say InstantiateIn(System.Web.UI.Control) exists in my contract assemblies and that implies a dependency on ASP.NET Web Forms.

I've been thinking about some double dispatch mechanism or even visitor pattern to try and work around this.

© Stack Overflow or respective owner

Related posts about mvp

Related posts about c#