需要一些关于使用 MVC 2 开始新生活的建议以及在 MVC2 中使用哪些 RAD 工具?
我终于决定搭上 MVC 2 的列车了。 我最近阅读了大量书籍,下面的架构我认为对于大多数商业 Web 应用程序来说已经足够了。
分层架构:-
模型(与数据库通信的层)。 EF4
存储库(与模型通信并包含所有查询的层)
业务层(验证、辅助函数、存储库调用)
控制器(控制应用程序的流程并负责从业务层向视图提供数据。)
视图(UI)
现在我决定为每一层创建一个单独的项目(只是为了尊重关注点分离的困境。虽然我知道这是没有必要的,但我认为这使项目看起来更专业:-)
我正在使用 AutoMetaData 用于验证的 t4 模板。我还遇到过 FluentValidation 但找不到太多相关信息。我应该选择哪一个?
选择哪个视图引擎?
Razor View Engine 一见钟情。但它仍处于测试阶段,我认为找到它的例子并不容易。我说得对吗?
Spark ..我也找不到太多关于它的信息,并且不想在没有人听的时候陷入中间的某个地方寻求帮助......:-(
T4 模板自动生成视图,我可以自定义它们以我想要的方式生成视图?这可以用 razor 和 Spark 实现吗?还是我必须手动创建它们?
如果
我能看到一个基于该项目的项目,我将非常感激。
请让我知道这是否是一个值得遵循的架构。 我对业务层有些困惑,比如这真的有必要吗?
I have finally decided to hop up on the train of MVC 2.
Now I have been doing a lot of reading lately and following is the architecture which I think will be good enough for most Business Web Applications.
Layered Architecture:-
Model (layer which communicates with Database). EF4
Repository (Layer which communicates with Model and includes all the queries)
Business Layer (Validations, Helper Functions, Calls to repository)
Controllers (Controls the flow of the application and is responsible for providing data to the view from the Business Layer.)
Views (UI)
Now I have decided to create a separate project for each layer (Just to respect the separation of concerns dilemma. Although I know it's not necessary but I think it makes the project look more professional :-)
I am using AutoMetaData t4 template for Validation. I also came across FluentValidation but cant find much on it. Which one should I go with?
Which View Engine to go for?
Razor View Engine Was Love at first sight. But it's still in beta and I think it won't be easy to find examples of it. Am I right?
Spark .. I can't find much on it either and don't want to get stuck somewhere in the middle crying for help when there is no one to listen...:-(
T4 templates auto generate views and I can customize them to generate the views the way I want? Will this be possible with razor and spark or do I have to create them manually?
Is there any way to Auto generate the repositories?
I would really appreciate it if I can see a project based on the architecture above.
Kindly to let me know if it's a good architecture to follow.
I have some confusion on the business layer like is it really necessary?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一个非常广泛的问题。我决定将 Fluent NHibernate 的自动配置功能用于新建应用程序,并且给我留下了深刻的印象。我的很多同事都使用 CakePHP,只需很少的配置即可生成与 cake 使用的默认约定兼容的数据库模式,这对我们来说非常有用。
This is a very broad question. I decided to use Fluent NHibernate's autoconfig feature for a greenfield application, and was quite impressed. A lot of my colleagues use CakePHP, and it needed very little configuration to get it to generate a database schema compatible with the default conventions cake uses, which is great for us.
我强烈推荐《ASP.NET MVC2 in Action》这本书。本书很好地涵盖了用于创建可维护的 ASP.NET MVC 应用程序的库生态系统。
至于视图引擎的选择,这可以取决于您的背景。我个人更喜欢我的视图看起来尽可能像 HTML,所以我会选择 Spark。另一方面,如果您习惯使用 ASP.NET classic,WebForms 视图引擎可能会让您最快地启动和运行。
I highly suggest the book ASP.NET MVC2 in Action. This book does a good job at covering the ecosystem of libraries that are used in making a maintainable ASP.NET MVC application.
As for the choice of view engines, that can depend on your background. I personally prefer my view to look as much like the HTML as possible, so I would choose Spark. On the other hand if you are used to working with ASP.NET classic, the WebForms view engine may get you up and running fastest.
这是一个很好的开始 - 我建议您添加的唯一一件事是业务逻辑和数据访问之间的抽象层(即:依赖关系反转/注入) - 请参阅此: 依赖倒置简介。
哈!通常你会发现很多“东西”并不是必要的 - 直到它需要的那一刻,那时通常已经太晚了。
重新查看引擎:我自己还是 ASP.NET MVC 的新手,因此不熟悉您所谈论的视图引擎;如果我是你,我会想象一些测试场景,然后尝试用每个产品来解决它们,这样你就可以直接比较它们。通常,您需要采取一些措施才能使试驾变得更加舒适 - 尽管这可能需要时间,但通常是值得的。
编辑:
首先,PM 通常不是技术主管;您负责解决方案的设计,而不是 PM。这并不罕见,根据我的经验,大多数时候,PM 甚至没有意识到他们正在侵犯你并不存在的地盘。这并不是说我是一个“政治土地掠夺者”,但我只是倾向于考虑“关注点分离”,嗯,我相信你明白。
作为设计师/架构师,您需要解释需求并(考虑业务优先级)提出提供最佳“平台”的解决方案。
如果你用枪指着我的头,我会说是的,但现实世界要复杂一些。
如果您对这些问题中的任何一个回答“是”,那么使用 DI 更有可能是一个好主意:
我还想指出,虽然肯定有一个学习曲线,但它并没有那么大,一旦你跟上速度,你仍然至少会像现在一样快;或者在最坏的情况下,你会花费更长的时间,但你会提供更多的价值(相对较少的努力)。
就涉及多少努力而言......
一次性任务(除了让团队加快速度之外):
“新”常见任务(假设您遵循本文中采用的方法):
您现在要做的事情可能会有所不同:
It's a fine start - the only thing I would suggest you add is a layer of abstraction between your Business Logic and Data Access (i.e: Dependency Inversion / Injection) - see this: An Introduction to Dependency Inversion.
Ha! Usually you'll find that a lot of "stuff" isn't necessary - right up until the moment when it is, at which point it's usually too late.
Re View Engines: I'm still a newbie to ASP.NET MVC myself and so aren't familiar with the view engines your talking about; if I were you I'd dream up some test scenarios and then try tackling them with each product so you can directly compare them. Often, you need to take things for a test drive to be more comfortable - although this might take time, but it's usually worth it.
Edit:
Firstly, PM's are not tech leads (usually); you have responsibility for the design of the solution - not the PM. This isn't uncommon, in my experience most of the time the PM isn't even aware they are encroaching on your turf that isn't theres. It's not that I'm a "political land grabber" but I just tend to think of "separation of concerns" and, well, I'm sure you understand.
As the designer / architect it's up to you to interpret requirements and (taking business priorities into account) come up with solution that provides the best 'platform' going forward.
If you put a gun to my head I would say yes, however the real world is a little more complex.
If you answer yes to any of these questions then its more likely using DI would be a good idea:
Id also like to point out that whilst there's definitely a learning curve involved it's not that huge, and once you're up-to-speed you'll still be at least as fast as you are now; or at worst you;ll take a little longer but you'll be providing much more value (with relatively less effort).
In terms of how much effort is involved...
One-Off Tasks (beyond getting the team up to speed):
'New' Common Tasks (assuming you're following the approach taken in the article):
Things you do now that you'd do differently:
有时从代码中学习模式要容易得多:Sharp 架构是 MVC 中良好实践的具体实现,使用 DDD。
Sometimes it is way more easy to learn patterns from code : Sharp Architecture is a concrete implementation of good practices in MVC, using DDD.