asp.net-mvc – 重用MVC arhitecture;有两层UI:ASP.NET MVC和.NET Winfo
|
虽然我的问题看似抽象,但我希望不是.假设我开发了一个应用程序,一个ASP.NET MVC站点,后来我的任务是为这个应用程序构建一个 Winforms客户端,以及如何从现有应用程序中重用它? 我定义了模型,我定义了控制器和视图.他们都运作良好. 现在老板要求Winforms客户端,我希望我可以重用模型和控制器(假设我把它们放在不同的程序集中)而不是只重用视图(ASPX视图). 可以这样做吗?怎么样? 解决方法我以前做过这个,不是使用asp.net MVC,而是使用纯asp.net网页表单.我使用了自己开发的MVP(模型 – 视图 – 展示器)模式,并且允许在WinForms应用程序中使用Presenter(在您的情况下为== Controller)的绝对最重要的事情是不引用与系统有关的任何事情名.web所以你需要做的第一件事是引入接口来包装任何请求,响应,web等东西,并让每个Presenter通过依赖注入接受这些接口(或通过其他技术使它们可供Presenters使用),然后如果Presenter使用那些而不是实际的system.web东西. 例: 想象一下,您想要将控制权从页面A转移到页面B(在您的winforms应用程序中,您可能希望关闭表单A然后打开表单B). 接口: public interface IRuntimeContext
{
void TransferTo(string destination);
}
网络实施: public class AspNetRuntimeContext
{
public void TransferTo(string destination)
{
Response.Redirect(destination);
}
}
winforms实现: public class WinformsRuntimeContext
{
public void TransferTo(string destination)
{
var r = GetFormByName(destination);
r.Show();
}
}
现在是演示者(在你的情况下控制器): public class SomePresenter
{
private readonly runtimeContext;
public SomePresenter(IRuntimeContext runtimeContext)
{
this.runtimeContext = runtimeContext;
}
public void SomeAction()
{
// do some work
// then transfer control to another page/form
runtimeContext.TransferTo("somewhereElse");
}
}
我没有详细研究过asp.net MVC实现,但是我希望这能给你一些指示,即启用你所使用的场景可能需要做很多工作. 您可能希望考虑接受必须为不同平台重新编码View和Controller,而是集中精力保持控制器非常薄,并将大部分代码放在可共享的服务层中. 祝好运! (编辑:安卓应用网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- asp.net-web-api – 如何只获取没有值的Odata.Count
- asp.net-mvc – ASP.NET MVC视图或URL应该有多少级别?
- asp.net-mvc-2 – 如何使用Castle Windsor在MVC中注入UrlHe
- asp.net – HttpServerUtility.UrlPathEncode vs HttpServe
- .net – 从控制器返回一个EditorTemplate作为部分视图
- asp.net – 如果缓存破坏程序与内容不匹配,防止捆绑包响应
- 管理页面来管理asp.net会员提供商和角色管理
- ASP.NET通过分布式Session提升性能
- asp.net-mvc-3 – SmtpClient.SendAsync阻止我的ASP.NET MV
- asp.net-mvc-3 – 找不到布局页面“{path}”
- 使用ASP.NET MVC 3和实体框架4.1代码首先在SQL C
- asp.net – MVC3何时使用区域?
- One to One 的数据库模型设计与NHibernate配置
- asp.net – 如何使用CSS垂直向下移动div
- asp.net-mvc – 如何阻止Elmah伐木?
- asp.net – 如何使用JSON方法序列化javascript对
- ASP.NET OpenWebConfiguration失败
- asp.net-mvc-4 – MVC 4 DropDownListFor错误 –
- asp.net – 在非开发环境中省略从Web API方法返回
- asp.net – 安装更新KB3154070后,iframe不会在IE
