脱钩的观点,介绍和ASP.NET Web窗体 [英] Decoupling the view, presentation and ASP.NET Web Forms

查看:104
本文介绍了脱钩的观点,介绍和ASP.NET Web窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有演示需要与控制来填充ASP.NET Web窗体页。这种相互作用是页面生命周期有些敏感,我想知道,如果有一招吧,我不知道。

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.

目前我有这样的:

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

本合同对System.Web.UI.Control的依赖,我需要这是能够做到的事情与ASP.NET Web窗体编程模型。但是,无论是观点还是主持人可能对ASP.NET服务器控件的知识。

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.

我如何解决这个问题?我怎样才能用的ASP.NET Web窗体工作的编程模型在我的具体看法,并没有采取在我的合同组件的System.Web.UI.Control依赖?

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?

要澄清事情有点,这种类型的接口是所有关于(使用MEF)UI组成。它贯穿了框架已知的,但它实际上只是从具体的视图中调用。具体的观点仍然是知道的ASP.NET Web窗体的唯一的事情。然而这些公共的方法说 InstantiateIn(System.Web.UI.Control)存在于我的合同组件,而且意味着对ASP.NET Web窗体的依赖关系。

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 but I don't yet know in which direction I want to go and I would really like some input on the matter.

推荐答案

不知道访问者是如何解决这个问题。但是,为什么没有你的合同是这样的:

Not sure how a visitor would solve the problem. But why not have your contracts look like this:

public interface ISomeContract
{
    void InstantiateIn(IControl container); 
}



用的iControl实现,可能在另一个程序集,让您的承包装配干净,它包装在ASP.NET System.Web.Control,如:

with an IControl implementation, possibly in another assembly to keep your contract assembly clean, that wraps over the ASP.NET System.Web.Control, like:

public class AspnetControl : IControl
{
    public AspnetControl(System.Web.Control control) { }

    // IControl members that dispatch to control
}

虽然有很高的可能性,最终的iControl最终会看起来很像一个System.Web.Control(从而战胜摆在首位它抽象的点) ,它仍然会非常检验的,你的观点和主持人不会知道有关ASP.NET的事情。

Although there's a high likelihood that eventually IControl would end up looking very much like a System.Web.Control (and hence defeat the point of abstracting it in the first place), it'd still be very testable, and your view and presenters won't have to know a thing about ASP.NET.

这篇关于脱钩的观点,介绍和ASP.NET Web窗体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆