开发者

Need some advice on starting a New Life with MVC 2 and which Tools to use for RAD in MVC2?

开发者 https://www.devze.com 2023-01-23 09:16 出处:网络
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 Applicat

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.

Lay开发者_StackOverflow社区ered 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?


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.


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.


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.


Sometimes it is way more easy to learn patterns from code : Sharp Architecture is a concrete implementation of good practices in MVC, using DDD.

0

精彩评论

暂无评论...
验证码 换一张
取 消