views:

48

answers:

4

Dear All

I have finally decided to hop up on the train of MVC 2. Now i have doing alot of reading lately and following is the architecture, which i think will be good enough for most of Business Web Application.

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 application and responsible to provide data to view from Business Layer.) Views (UI)

Now i have decided to create a separate project for each layer (Just to respect the separation of concern dilemma. Although i know its not necessary but i think it makes the project looks 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 the Love at first sight. but its still in beta and I think it wont be easy to find examples on it.Am I right? Spark .. I cant find much on it either and dont wanna get stuck somewhere in the middle and crying for help when there is no one to listen...:-(

T4 templates auto generates 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 if I can see a project based on the architecture above?

Kindly to let me know if its a good architecture to follow? I have few confusions on the business layer like is it really necessary?

Thanks and Regards

Dani

A: 

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.

mootinator
A: 

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.

Dennis Burton
A: 

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.
Adrian K