ASP.NET MVC3中Controller的设计模式 [英] Design pattern for Controller in ASP.NET MVC3

查看:106
本文介绍了ASP.NET MVC3中Controller的设计模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有Dynamics CRM 2011公开的WCF服务,以及一个使用这些服务的ASP.NET MVC3门户.
我必须从控制器调用WCF服务,但我不想直接从控制器调用WCF服务.我可以想到以下模式

•服务立面

•控制器级别的DI和IoC


就此方案的模式而言,最佳实践是什么.

谢谢

I have WCF Services exposed by dynamics CRM 2011, and a ASP.NET MVC3 portal to consume these services.

I have to make call to WCF services from controller and I don''t want to make call to WCF services directly from controller. I can think of following patterns

•Service Facade

•DI and IoC at controller level


What is the best practice in terms of patterns for this scenario.

Thanks

推荐答案

嗨!通常,访问Web服务(或 WCF )应由 MVC 模式的模型部分封装.由于 ASP.NET MVC 并未规定如何组织模型类的规则,因此您必须自己做出决定.使您的模型类公开 MVC 控制器将使用的接口.这些界面可以是 CRM 服务本身的合同,也可以是其他形式,具体取决于您的情况-它们将成为您提到的 Service Facade .使用 IoC/DI MVC 控制器获取接口的对象实例.并且(只是为了确保):在这种情况下应使用 AsyncController .而已.请随时跟进其他问题.
Hi! In general, accessing web (or WCF) services should be encapsulated by the Model part of the MVC pattern. Since ASP.NET MVC does not prescribe rules of how your model classes should be organized, you have to make those decisions by yourself. Make your model classes expose interface(s) that will be consumed by MVC controllers. Those interfaces can be the contracts of CRM services themselves, or something different, depending on your situation -- they will be the Service Facade that you mentioned. Use IoC/DI to let MVC controllers obtain object instances for the interfaces. And (just to make sure): AsyncController should be used in this scenario. That''s it. Please feel free to follow up with any additional questions.


这篇关于ASP.NET MVC3中Controller的设计模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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