创建新项目的良好实践

发布于 2024-11-02 04:50:59 字数 437 浏览 1 评论 0 原文

我需要创建一个新网站,我已经完成了数据库建模并且需要启动它,我还想使用 MVC 和 LinqToSql。

我的老板说我可能需要为 Windows Phone 7 创建一个应用程序。

当我从事此工作时,我从不遵循任何良好的实践或模式,我的意思是,当用户单击网页中的“注册”按钮时,我创建 DataContext 的一个实例,验证输入等,所有这些都在该按钮单击的事件处理程序内。

那么,当我需要制作 WP7 应用程序时该怎么办?我必须再次复制并粘贴代码吗?我知道我应该重用它,但我实际上不知道如何、我应该在哪里放置业务规则、数据访问等...

我正在阅读有关企业模式的内容,但我发现它对我来说太复杂了,因为我不这样做还没有太多经验。

请就此向我提出建议。

另外,如果您能为我指出一个很好的示例项目,我可以检查其源代码并遵循相同的架构,那就太好了!

谢谢!

I need to create a new website, I have the database modeling done and I need to start it, I also want to use MVC and LinqToSql.

My boss said that I'll might need to create an app for Windows Phone 7.

I never follow any good practice or pattern when I'm working on this, what I mean is, when a user clicks a Register button in a web page, I create an instance of my DataContext, validate the input and etc all inside the event handler for that button click.

So, what about when I need to make the WP7 app? I'll have to copy and paste the code again? I know that I should reuse it, but I don't know actually how, where should I place the business rules, data access etc...

I was reading about Enterprise Patterns, but I found it too complicated for me as I don't have much experience yet.

Please advice me on this.

Also, if you can point me to a good sample project that I can check its source code and follow the same architecture, would be great!

thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

无尽的现实 2024-11-09 04:50:59

Sharp 架构是 MVC 架构和项目结构的著名示例。

http://wiki.sharparchitecture.net/(X(1)S(rcnk1jfg1daywk55iazwqh55))/default.aspx?AspxAutoDetectCookieSupport=1

当然,您可以根据具体情况以不同方式设置您的项目您的需求,但这是一个很好的例子。

此外,对于数据访问,存储库模式也被广泛使用。这是一篇关于使用实体框架在 MVC 中实现该模式的好文章...

http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4- 0.aspx

祝你好运!

Sharp architecture is a well known sample of MVC architecture and project structure.

http://wiki.sharparchitecture.net/(X(1)S(rcnk1jfg1daywk55iazwqh55))/default.aspx?AspxAutoDetectCookieSupport=1

Of course, you may set up your project differently depending on your needs, but this is a great example to start with.

Also, for data access, the Repository pattern is widely used. Here is a good article for implementing the pattern in MVC using Entity Framework...

http://blogs.msdn.com/b/adonet/archive/2009/06/16/using-repository-and-unit-of-work-patterns-with-entity-framework-4-0.aspx

Good Luck!

最后的乘客 2024-11-09 04:50:59

您应该考虑转向 N 层设计,将您的 UI 与 Biz 和 Dal 分开。
这还允许在手机应用程序或您可能需要的任何其他地方重用您的业务逻辑和 Dal。

这是一篇博客文章,涵盖了您需要执行的操作N 层设计重访 这是涵盖 N 层设计的 5 篇文章中的第一篇,我包含一些代码示例,并有一些项目可供查看存储库。

另一个建议是获取 Head First Design Patterns 的副本来学习设计模式,并开始研究学习最佳实践。好的设计与技术无关,你应该花与构建它一样多的时间来学习如何设计某些东西。

You should look at moving to N-tier design, separate your UI from the Biz from the Dal.
This also allows reuse of your biz logic and Dal in the phone app, or any where else you might need to.

Here is a blog post that kind of covers what you are going to need to do N-Tier Design revisit this is the first of 5 posts covering N-Tier design, I include some code samples and have some projects to look at in the repository.

Another suggestion is to get a copy of Head First Design Patters to learn design patterns, and start looking at learning best practices. Good design is technology agnostic, you should spend as much time learning how to design something as you do what you're building it in.

烟雨扶苏 2024-11-09 04:50:59

MVP 设计模式正是您所寻找的!

我处于类似的情况(在不同屏幕尺寸/框架上的移动设备和桌面设备之间共享的应用程序),并且通过使用此模式,业务代码是相同的,您不需要复制代码。

The MVP design pattern is what you're looking for !

I'm in a similar case (an application shared between mobile & Desktop on different screen sizes / frameworks) and by using this pattern the Business code is the same and you don't need to duplicate your code.

烟若柳尘 2024-11-09 04:50:59

使用 MVC 的一个好处是您的操作实际上可以返回 JsonResult,并成为 WP7 客户端应用程序的公开服务 API。

我建议研究一下这个问题,以及stephen776的建议;然后,您的 MVC 应用程序将使用您的存储库(数据访问)和实体(模型),然后将它们公开给 Web 浏览器(使用 MVC 视图/Javascript)和外部应用程序(使用 JSON 结果)。

对于 WP7 应用程序,最好使用的模式称为模型-视图-视图模型 (MVVM),它依赖于称为数据绑定的强大 Silverlight 功能,也请尝试研究一下。有一组很好的库旨在帮助您http://mvvmlight.codeplex.com/

One good thing about using MVC is that your actions can actually return JsonResult, and become an exposed service API for your WP7 client app.

I would suggest looking into that, along with what stephen776 has suggested; your MVC app would then be the one to consume your Repositories (Data Access) and Entities (Model), and then expose them to both web browsers (using MVC Views/Javascript) and external apps (using JSON results).

For the WP7 app, the best pattern to use is called Model-View-ViewModel (MVVM) and it relies in a powerful Silverlight feature called DataBinding, try looking into that as well. There exists a good set of libraries aimed to help you with that http://mvvmlight.codeplex.com/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文