需要一些关于使用 MVC 2 开始新生活的建议以及在 MVC2 中使用哪些 RAD 工具?

发布于 2024-09-30 00:27:33 字数 736 浏览 2 评论 0原文

我终于决定搭上 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 技术交流群。

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

发布评论

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

评论(4

习ぎ惯性依靠 2024-10-07 00:27:33

这是一个非常广泛的问题。我决定将 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.

ぽ尐不点ル 2024-10-07 00:27:33

我强烈推荐《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.

浮云落日 2024-10-07 00:27:33

<块引用>

请告诉我这是否是一个值得遵循的良好架构?

这是一个很好的开始 - 我建议您添加的唯一一件事是业务逻辑和数据访问之间的抽象层(即:依赖关系反转/注入) - 请参阅此: 依赖倒置简介

<块引用>

我知道它没有必要,但我认为它使项目看起来更专业:-)

哈!通常你会发现很多“东西”并不是必要的 - 直到它需要的那一刻,那时通常已经太晚了。

重新查看引擎:我自己还是 ASP.NET MVC 的新手,因此不熟悉您所谈论的视图引擎;如果我是你,我会想象一些测试场景,然后尝试用每个产品来解决它们,这样你就可以直接比较它们。通常,您需要采取一些措施才能使试驾变得更加舒适 - 尽管这可能需要时间,但通常是值得的。

编辑:

<块引用>

如果我向我的 PM 推荐这一层并给出上述两个原因,那么我认为他不会接受

首先,PM 通常不是技术主管;您负责解决方案的设计,而不是 PM。这并不罕见,根据我的经验,大多数时候,PM 甚至没有意识到他们正在侵犯你并不存在的地盘。这并不是说我是一个“政治土地掠夺者”,但我只是倾向于考虑“关注点分离”,嗯,我相信你明白。

作为设计师/架构师,您需要解释需求并(考虑业务优先级)提出提供最佳“平台”的解决方案。

<块引用>

(关于 DI)我的问题是,这真的值得吗?

如果你用枪指着我的头,我会说是的,但现实世界要复杂一些。

如果您对这些问题中的任何一个回答“是”,那么使用 DI 更有可能是一个好主意:

  • 该系统并非平凡
  • 系统的预期寿命超过(不确定此处正确的数字是多少,可能没有) t,所以我打算在两年后在地上放一根木桩。
  • 系统和/或其要求是可变的。
  • 将工作(BL / DAL)拆分到不同的团队将对项目有利(也许您是分布式团队的一部分)。
  • 该系统面向具有多样化技术环境的市场(例如:并非每个人都想使用 MS SQL)。
  • 您想要执行质量测试(这会让事情变得更容易)。
  • 该系统很大/很复杂,因此可以将功能拆分并放入其他系统中。
  • 您希望提供不止一种存储数据的方法(例如免费的基于文件的存储库和收费的数据库驱动的存储库)。
  • 业务驱动因素/环境是不稳定的 - 如果他们来找你说“这很棒,但现在我们想提供基于云的版本,你能把它放在 Azure 上吗?”

我还想指出,虽然肯定有一个学习曲线,但它并没有那么大,一旦你跟上速度,你仍然至少会像现在一样快;或者在最坏的情况下,你会花费更长的时间,但你会提供更多的价值(相对较少的努力)。

就涉及多少努力而言......

一次性任务(除了让团队加快速度之外):

  • 编写提供程序加载器或选择 DI 框架。完成此操作后,它将可以在您的所有项目中重复使用。

“新”常见任务(假设您遵循本文中采用的方法):

  • 定义接口(在纸上)- 无论如何,这都是您现在要做的事情,只是您可能没有意识到。基本上它是面向对象设计,但由于它将成为两个或多个包之间的正式接口,因此您需要考虑一下(是的,您仍然可以重构它 - 但理想情况下,接口应该“稳定”并且不会发生太大变化;如果确实发生变化,最好“添加”而不是“删除或更改”现有成员)。
  • 编写接口代码。这非常快(几分钟而不是几小时),因为您没有编写任何实现;当你去实现时,你可以使用 IDE 提供的工具来生成基于接口的代码存根。

您现在要做的事情可能会有所不同:

  • 实例化一个变量(在您的 BL 类中)来保存提供程序,可能是通过工厂。编写此内容不会花费很长时间(再次强调,几分钟而不是几小时),并且复制、粘贴和复制代码相当简单。在需要时重构。
  • 编写DAL代码:应该和以前一样。

Kindly to let me know if its a good architecture to follow?

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.

i know its not necessary but i think it makes the project looks more professional :-)

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:

If i suggest this layer to my PM and give him the above two reasons then i don't think he will accept it

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.

(Regarding DI) My question is , is it really worth it?

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:

  • The system is non-trivial
  • The expected life of the system is more than (not sure what the right figure is here, there probably isn't one, so I'm going to put a stake in the ground at) 2 years.
  • The system and/or its requirements are fluid.
  • Splitting up the work (BL / DAL) into different teams would be advantageous to the project (perhaps you're part of a distributed team).
  • The system is intended for a market with a diverse technical landscape (e.g: not everyone will want to use MS SQL).
  • You want to perform quality testing (this would make it easier).
  • The system is large / complex, so splitting up functionality and putting it into other systems is a possibility.
  • You want to offer more than one way to store data (say a file based repository for free, and a database driven repository for a fee).
  • Business drivers / environment are volatile - what if they came to you and said "this is excellent but now we want to offer a cloud-based version, can you put it on Azure?"

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):

  • Writting a Provider Loader or picking DI Framework. Once you've done this it will be reusable in all your projects.

'New' Common Tasks (assuming you're following the approach taken in the article):

  • Defining interface (on paper) - this is something you'll be doing right now anyway, except that you might not realise it. Basically it's OO Design, but as it's going to be the formal interface between two or more packages you need to give it some thought (and yes you can still refactor it - but ideally the interface should be "stable" and not change a lot; if it does change it's better to 'add' than to 'remove or change' existing members).
  • Writting interface code. This is very fast (minutes not hours), as you're not writting any implementation; and when you go to implement you can use tools provided by your IDE to generate code-stubs based on the interface.

Things you do now that you'd do differently:

  • Instantiating a variable (in your BL classes) to hold the provider, probably via a factory. Writting this shouldn't take long (again, minutes not hours) and it's fairly simple code to copy, paste & refactor where required.
  • Writing the DAL code: should be the same as before.
谁许谁一生繁华 2024-10-07 00:27:33

有时从代码中学习模式要容易得多: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.

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