1

In my last question I posted some sample code on how I was trying to achieve separation of concerns. I received some ok advice, but I still just don't "get it" and can't figure out how to design my app to properly separate concerns without designing the next space shuttle.

The site I am working on (slowly converting from old ASP section by section) is moderately sized with several different sections including a store (with ~100 orders per day) and gets a decent amount of traffic (~300k uniques/month). I am the primary developer and there might be at most 2-3 devs that will also work on the system.

With this in mind, I am not sure I need full enterprise level architecture (correct me if i am wrong), but since I will be working on this code for the next few years, I want it to perform well and also be easy to extend as needed. I am learning C# and trying to incorporate best practices from the beginning. The old ASP site was a spaghetti mess and I want to avoid that this time around.

My current stab at doing this ended up being a bunch of DTOs with services that validate and make calls to a DAL layer to persist. It was not intentional, but I think the way it is setup now is a perfect anemic domain model. I have been trying to combat this by turning my BLL to domain objects and only use the DTOs to transfer data between the DAL and BO, but it is just not working. I also had all my dtos/blls split up according to the database tables / functionality (eg - YouTube style app - I have separate DTO/BLL/DAL for segments, videos, files, comments, etc).

From what I have been reading, I need to be at least using repositories and probably interfaces as well. This is great, but I am unsure how to move forward. Please help!

Community
  • 1
  • 1
jpshook
  • 4,834
  • 6
  • 36
  • 45
  • 4
    All other things being equal, simpler is better. If your application is not a large-scale, enterprise application, you may not need all that ceremony. The Nerddinner architecture is a good example of a simple, decoupled architecture that can scale from the smallest of sites to a larger one. You might want to study it: http://nerddinnerbook.s3.amazonaws.com/Intro.htm – Robert Harvey Mar 21 '11 at 15:59
  • 1
    Whatever you build, it will be vastly better than the spaghetti you had with the classic ASP site. – Robert Harvey Mar 21 '11 at 16:01
  • @Robert Harvey - Thanks for your comments. The Nerd dinner project is MVC, correct? Will their architecture work in a web forms environment? I currently have a few web forms and the classic ASP pages, should I consider also merging in MVC to this mess? – jpshook Mar 21 '11 at 17:40
  • See [this article by Scott Hanselman.](http://www.hanselman.com/blog/PlugInHybridsASPNETWebFormsAndASPMVCAndASPNETDynamicDataSideBySide.aspx) It describes how Webforms can run side-by-side with ASP.NET MVC, although you should consider making them MVC pages. The ASP pages should be rewritten from scratch. Caveat: The Hanselman article is a bit dated. – Robert Harvey Mar 21 '11 at 18:05
  • Do you really think it would be worth it to mix MVC into such a already complex project? What is MVC going to give me? – jpshook Mar 21 '11 at 18:55
  • For the benefits of ASP.NET MVC, see http://stackoverflow.com/questions/102558/biggest-advantage-to-using-asp-net-mvc-vs-web-forms and http://weblogs.asp.net/scottgu/archive/2007/10/14/asp-net-mvc-framework.aspx. Pure MVC is simpler, not more complicated, than what you are proposing in your question. – Robert Harvey Mar 21 '11 at 18:57
  • It's probably worth migrating to MVC if you can. It's probably not worth having both webforms and MVC in one project. Sure, it's possible but the two frameworks are based on such different philosophies that you'll be much happier being able to stick with one and master it. – Robert Levy Mar 22 '11 at 02:13
  • Well, I already have a certain level of proficiency with web forms, but am a complete Noob at MVC. Plus, getting MVC to integrate into my current web forms website is proving to be next to impossible... :( – jpshook Mar 22 '11 at 20:42
  • In traditional MVC you push the control events back into the Controller. This is a pretty major departure from your current web forms approach. I would suggest you consider one of the MVP variants where the basic control events like button clicks can stay in your web form which is now also a View implementation, and the Presenter is responsible for the heavy lifting in terms of moving data in and out of the view, but Presenter does not go so far as to actually respond to low level control events like the initial button clicks. – Sisyphus Mar 22 '11 at 23:23

2 Answers2

3

From what I can see you have four points that need addressing:

(1) "With this in mind, I am not sure I need full enterprise level architecture"

Lets deal with the high level fluff first. It depends on what you mean by "full enterprise level architecture", but the short answer is "Yes" you need to address many aspects of the system (and it will depend on the context of the system as to what the main ones are). If nothing else, the keys ones would be Change and Supportability. You need to structure the application in a way that supports changes in the future (logical and physical separation of concerns (Dependency Injection is a great for the latter); modular design, etc).

(2) "How to properly separate concerns in my architecture without designing a spacecraft?"

I like this approach (it's an article I wrote that distilled everything I had learnt up to that point) - but here's the gist: enter image description here

Looking at this you'll have a minimum of six assemblies - and that's not huge. If you can break your system down (separate concerns) into these large buckets it should go a long way to giving what you need.

(3) Detail

Separating concerns into different layers and classes is great but you need to go further than that if you want to be able to effectively deal with change. Dependency Inversion (DI) is a key tool to use here. When I learnt DI it was a hand-rolled affair (as shown in the previous link) but there are lots of frameworks (etc) for it now. If you're new to DI (and you work in .Net) the article will step you through the basics.

(4) How to move forward

Get a simple vertical slice (UI all the way to the DB) working using DI, etc. As you do this you'll also be building the bones of the framework (sub-systems and major plumbing) that your system will use.

Having got that working start on a second slice; it's at this point that you should uncover any places where you're inadvertently not reusing things you should be - this is the time to change those before you build slices 3,4 and 5 - before there's too much rework.

Updates for Comments:

Do you you think I should completely drop web forms and take up MVC from scratch or just with what I know for now?

I have no idea, but for the answer to be 'yes' you'd need to be able to answer these following questions with 'yes':

  • We have the required skills and experience to use and support MVC.
  • We have time to make the change (there is clear benefit in making this change).
  • We know MVC is better suited for our needs.
  • Making this change does not put successful delivery at risk.

...do I need to move to projects and setup each of these layers as a separate project?

Yes. Projects map 1-to-1 with assemblies, so get the benefits of loose-coupling you'll definitely want to separate things that way, and be careful how you set references.

when you refer to POCOs, are you meaning just DTOs or rich domain objects?

DTO not Rich Domain Object. BUT, people seem yo use the terms POCO and DTO interchangeably when strictly speaking they aren't - if you're from the Martin Fowler school of thought. In his view a DTO would be a bunch of POCO's (or other objects(?)) parcelled together for sending "across the wire" so that you only make one call to some external system and not lots of calls.

Everyone says I should not expose my data structures to my UI, but I say why not?

Managing dependencies. What you don't want is for you UI to reference the physical data structure because as soon as that changes (and it will) you'll be (to use the technical term) screwed. This is the whole point of layering. What you want to do is have the UI depend on abstractions - not implementations. In the 5-Layer Architecture the POCOs are safe to use for that because they are an abstract / logical definition of 'some thing' (a business concept) and so they should only change if there is a business reason - so in that sense they are fairly stable and safer to depend on.

Adrian K
  • 9,880
  • 3
  • 33
  • 59
  • @Adrian K - Thanks for taking the time to spell this out. Do you you think I should completely drop web forms and take up MVC from scratch or just with what I know for now? Also, right now my site is setup as a website in VS, do I need to move to projects and setup each of these layers as a separate project? – jpshook Mar 22 '11 at 20:46
  • @Adrian K - Also, when you refer to POCOs, are you meaning just DTOs or rich domain objects? – jpshook Mar 22 '11 at 20:56
  • @Adrian K - I am currently reading your PDF. Please check out my previous post at http://stackoverflow.com/questions/5147113/is-this-a-proper-implementation-of-n-layer-architecture , it seems like I am almost there, but just need to add some interfaces. I am just not sure how to fit the repositories/interfaces in. Also, everyone says I should not expose my data structures to my UI, but I say why not? – jpshook Mar 22 '11 at 20:59
  • @Developr - I'll try and have a look when I get some time :) But in essence the trick is to think about things from a logical / non-implementation / non-technology specific viewpoint. – Adrian K Mar 23 '11 at 04:05
  • @Adrian K - Do you have any sample projects where I can see how all the code and projects go together? I have no idea on how to a) migrate my 25,000+ files (including ASP, Images, videos, etc) into multiple project files. – jpshook Mar 23 '11 at 18:43
  • I would say 5 layers is too many abstractions for @Developr needs. Only use "just enough" abstractions to do proper unit testing. – JarrettV Mar 05 '13 at 14:51
  • @JarrettV - yes I totally agree; you just have to weigh up future growth and change to make sure you don't paint yourse'f into a corner by thinking too small. – Adrian K Apr 09 '13 at 04:26
2

If you are in the process of rewriting your eCommerce site, you should atleast consider replacing it with a standard package.

There are many more such packages available today. So although the decision to build the original site may have been correct, it is possible that building a custom app is no longer the correct decision.

There are several eConmmerce platforms listed here: Good e-commerce platform for Java or .NET

It should cost much less than the wages of 2-3 developers.

Community
  • 1
  • 1
Shiraz Bhaiji
  • 64,065
  • 34
  • 143
  • 252