Ayende @ Rahien

It's a girl

Review: Microsoft N Layer App Sample, Part II–getting lost in the architecture

Continuing my review of http://microsoftnlayerapp.codeplex.com/, an Official Guidance (shows up at: http://msdn.microsoft.com/es-es/architecture/en) which people are expected to read and follow.

So the first thing that I saw when I opened the solution was this:

image

Yes, I know that this is a sample application, and still, this bit scares me. I have never really used the modeling support inside VS, so I took a look there, to see what is going on.

Take a look at one of those:

image

Do you see the problem here?

As usual with those sort of questions, it is an issue of what is not here. There is not a single mention of the actual application. To be frank, at this point, all I know is that it is a sample application, but I don’t know what the sample is about.

This is pretty scary, because I am pretty sure that if this is the case at that level, we are going to see much the same as we go deeper. I decided that it might behoove me to figure out what this application is about, so I checked the database project, and found:

image

Um… so it looks like it is about a bank, but also about books, and orders and software. I don’t really see how they connect right now, but we will see, I hope.

Tags:

Posted By: Ayende Rahien

Published at

Originally posted at

Comments

Anon
06/30/2011 09:13 AM by
Anon

software is hard! right?

Kash
06/30/2011 09:33 AM by
Kash

I hope that you doesn't judge all software seeing only a layer diagram and a bunch of sql files... I think that this post is another "meaningless" assumption and not very much significative. I'm completely sure that you haven't read the book (http://download.microsoft.com/download/9/F/A/9FA4753A-FC8A-40DE-9EFA-CCAFB4C835FC/DDDNLayeredNET40ArchitectureGuideMicrosoft160513.zip). Please, read it first!!

Fer
06/30/2011 09:54 AM by
Fer

Do you know that there is a whole book explaining the architecture? I recommend you first read the book and review the code.

Today I reviewed the architecture codeplex page and there is an alpha version. I think it might be a good option to send your proposals.

Maybe is not the best architecture but I think it's a very good reference architecture on which you can look for your developments.

Parag Mehta
06/30/2011 10:08 AM by
Parag Mehta

Well people need to understand that we chose architecture based on requirements and not the other way around!

This is classic example of where SE is moving... It is moving away from what it was designed for.

You don't choose DDD just because you want it! You choose it if it's warranted.

I agree with Ayende, there is no need for such complicated mess if application is a "simple sample". I haven't looked around this project, but If I would have, I would started from looking at Test cases if SRS etc was not available.

Sergey Shishkin
06/30/2011 10:33 AM by
Sergey Shishkin

Code talks, book walks!

Code is the single point of truth. Get the code wrong and no book will be able to fix it.

Kash
06/30/2011 10:50 AM by
Kash

@Sergey

This is your personal point of view I hope...

Tom Pester
06/30/2011 11:18 AM by
Tom Pester

Read the manual that comes with it before spreading some FUD

This solutions comes with excellent documentation. We can't say that of all projects ... For once a project with quality documentation is released and it isn't even read before making ones mind.

If you want to figure out what this application does why not start with "1.4 Domain" ? Or the database if you prefer but that says less.

As the documentation states (and other commenters repeated) this massive categorization of the solution is only justified when working on big projects. Cesar went so far to make this guidance applicable when working on big projects. You have a point that the application that comes along with it is too small to demonstrate the usefulness of (indeed a massive) division into solution folder/projects.

But whats the point groking a big domain if the point of the project is too grok DDD applied to .NET? Use a bit of your imagination and think about the DDD concept of bounded contexts.

Just take a step back and leave out if something isn't justified.

Eric
06/30/2011 11:53 AM by
Eric

Ayende,

I always enjoy your blogs, but I now find myself skipping the blog and navigating directly to the comments.

Controversy. I love it!

btw: I believe Kash was one of the authors.

David Fauber
06/30/2011 12:01 PM by
David Fauber

"Do you know that there is a whole book explaining the architecture?"

Oh sweet, its hard for me to get behind solutions that don't come with a book to explain what's going on.

Erik Juhlin
06/30/2011 12:01 PM by
Erik Juhlin

I was just wondering when reading these posts... what happended to the Macto sample? :)

Steve
06/30/2011 12:50 PM by
Steve

Why is the fact that there is an entire book dedicated to this architecture considered a good thing? Why oh why does everything that comes out of Microsoft have to be so ridiculously complicated?

Simon
06/30/2011 12:58 PM by
Simon

+1 for macto! I've been waiting for that for ages!! :-)

Would be more than happy to pay towards the cost of it, but I guess Ayende's rates have gone up a bit in the last few years!! :-)

Kash
06/30/2011 12:58 PM by
Kash

@Eric

You are wrong. I'm one of the readers, and I use some of the concepts and ideas behind the guide and the code, not all. For me it has been a very helpful stuff in my daily work. Attitudes like this do not help anyone, only cause confusion. This produces me angry...

David Fauber
06/30/2011 01:09 PM by
David Fauber

"This produces me angry" ---> "This makes me angry"

('produce' as a verb means creating something tangible...use "make" for emotions etc)

Steve
06/30/2011 01:11 PM by
Steve

@Kash,

With all due respect, how does "attitudes like this" not help anyone? Oren was sent an email asking him to review the architecture, he is simply doing as requested.

When a movie critic gives a movie a bad review, is it the critic's fault that the movie wasn't good?

Dave
06/30/2011 01:20 PM by
Dave

First people bash Microsoft for doing drag-and-drop demos and now that they put something together that implements patterns people are complaining. What do you want Microsoft to write your app for you? The first thing to remember is that this is guidance. You would be a fool to take this whole example and implement it line by line. You need to design YOUR architecture to fit your needs. This app is just showing you what you could do with patterns and the .Net Framework. If you like the repository pattern great here is one way to implement it. If you want to use a Unit of Work, here is an implementation that seems to work.

This example taken as a whole as the gospel is the wrong way to look at it. The book that everyone seems to want to ignore was written first and the example was made to support it. The book does a good job of explaining why choices were made and in some cases some alternate courses of action. I agreed with different sections and other sections I think are completely wrong. In the end I learned a few tricks that I can implement in my architectures (when they are called for).

Robert Byrne
06/30/2011 01:25 PM by
Robert Byrne

@Steve

" is it the critic's fault that the movie wasn't good"

Better to say that the critic didn't think the movie was good, other people can disagree with his opinion, it doesn't make the software/movie any more or less 'good'.

Dave
06/30/2011 01:29 PM by
Dave

@Steve

I think that the problem is he is writing this review in parts. People are taking his initial impressions as a whole through evaluation of the project (code and book). It is interesting to get an insight into how he evaluates a project but I will wait for his final assessment before I would critique his critique.

Kash
06/30/2011 01:33 PM by
Kash

@Steve

Such criticisms are not constructive, at least until now. I will wait for the next posts to see if there are some compelling reasons to confirm what promise in their titles ...

JhonRed
06/30/2011 09:17 AM by
JhonRed

@Ayende...

Two cents..

1º Whether you do not agree with you, you keep forgetting (intentionally sure) of project scope:

"It is an Educational example, not a real world system, it shows educational scenarios, easy to understand useful from a patterns implementation point of view, but not necessarily as a whole business application. The architecture is decoupled and relatively complex so it would allow to grow your system."

2º You should be showing an old version of the solution because this is not what I've downloaded yesterday ... ummmmmmmmm!!

JhonRed
06/30/2011 10:49 AM by
JhonRed

@Sergey Shishkin,

You've downloaded the latest version, v2, and have seen the project?

http://microsoftnlayerapp.codeplex.com

Jhon R.Dt

Ayende Rahien
06/30/2011 01:38 PM by
Ayende Rahien

JhonRed, 1) I am well aware of the project scope, I am disagreeing with the ability to do what they want within that scope. 2) I am posting about the code that was available at the time that I wrote, which you can read at the bottom of the post.

Steve
06/30/2011 01:44 PM by
Steve

@Robert Byrne

Good point, my analogy should have been "is it the critic's fault he didn't like the movie".

People are free to disagree with any critic's opinion, don't tell the critic that having his opinion is wrong or unhelpful.

Secondly, Oren is known to be incredibly tough when he reviews code, yet they asked him to review the code. It's not like he went looking for a fight, they came to him.

Joe
06/30/2011 01:44 PM by
Joe

I would not dare to judge the architecture with this little information. But I agree with Steve that having to read a book in order to understand an architecture does not make it a "good" one. What is the point of a sample application if it is not self-explanatory :P especially if it is the goal to explain concepts.

BTW: this is also a nice talk about architectures in general:

http://www.infoq.com/presentations/Simplicity-Architect

Have fun

Ayende Rahien
06/30/2011 01:52 PM by
Ayende Rahien

Fer, I scanned through the book, yes. Nothing that was new or unfamiliar to me, same stuff as the original. And no, it doesn't make it better.

JhonRed
06/30/2011 01:53 PM by
JhonRed

I can not find the sense, that sense has to do a review of something that has changed?

Jhon R.D

Ayende Rahien
06/30/2011 01:54 PM by
Ayende Rahien

Tom, You can show off this architecture in a small project. It doesn't work. Worse, because it is a small application, they layered on a lot of stuff that is unneeded and harmful. They could get away with it because the application is less than northwind.

Ayende Rahien
06/30/2011 01:55 PM by
Ayende Rahien

Erik, I never got the time to do it.

Ayende Rahien
06/30/2011 01:57 PM by
Ayende Rahien

Dave, Maybe I would like to get quality guidance, you know, stuff that I can say I am happy to implement in my applications or see people implement?

Steve
06/30/2011 01:57 PM by
Steve

@Kash,

I'm not sure I get why his comments should be considered "not constructive". They're not flattering by any stretch, but he doesn't approve of the application. So is anything not praising the application "not constructive"?

Dave
06/30/2011 02:08 PM by
Dave

I agree quality guidance is important. I too think the example is too small to fit the architecture that they are promoting. In your opinion are there situations where this architecture would not be considered over kill? The projects that I work on would not warrant this structure as a whole but there are parts of it that are useful. I just think that it is nice to see a Microsoft example that doesn’t go from a data grid on a page directly to a database.

Kash
06/30/2011 02:09 PM by
Kash

@Steve

Because he does not provide any valid argument to say that something is wrong. I only see subjective and partial judgments.

Alex Simkin
06/30/2011 02:11 PM by
Alex Simkin

To all. The document is very good and it summarizes the majority of good patterns and practices of enterprise architecture. But look how thos patterns are implemented before bushing Ayende. Look how IoC container is called directly instead of infrastructure calling it. Look how DTO's are manually mapped to entities instead of infrastructure doing this.

Alex Simkin
06/30/2011 02:16 PM by
Alex Simkin

Off topic. I hate BlackBerry on-screen keyboard.

Ayende Rahien
06/30/2011 02:25 PM by
Ayende Rahien

Dave, That is really a complex answer, because it comes in two parts. * The architecture that they say they are advocating. * The architecture that they are actually advocating.

DDD has its place in big, complex applications where the major thing is complex business logic. What they did is a complex technological mess. I don't think the later should be used.

And I like going directly to the DB, there is rarely a good reason to want to wrap those things up.

Dave
06/30/2011 02:35 PM by
Dave

Do you like going directly to the DB from an aspx page? What is the reasoning? How is the performance for long running SQL Querys? Do you uses services?

Ayende Rahien
06/30/2011 02:45 PM by
Ayende Rahien

Dave, No, not that. But I see all too often people setting up 7 layers of indirection to do a single select. You can see my series of posts about the Whiteboard project for more details, here is one: http://ayende.com/blog/4784/architecting-in-the-pit-of-doom-the-evils-of-the-repository-abstraction-layer

Ayende Rahien
06/30/2011 02:46 PM by
Ayende Rahien

Dave A good way to see how I currently write applications is this sample app (also this blog): http://github.com/ayende/RaccoonBlog/

Dave
06/30/2011 02:52 PM by
Dave

Ok. That is what I mean when I say going directly against the database. I agree many layer of indirection are not necessary. I did see that post. For the most part I agree but there are times when a repository pattern makes the code a little cleaner. But you should not use repositories for the sake of using a pattern. You should apply the pattern when it makes sense.

That is one of the things I don't like about this N-Layer app is that they hide the data access behind repositories and specifications. They also like to implement patterns that are already implemented in the .Net Framework, for instance they recreate the Unit of Work when the ObjectContext is already a unit of work. A little over kill!

Dave
06/30/2011 03:00 PM by
Dave

Cool. I will check out your app.

peter
06/30/2011 03:01 PM by
peter

I hope I don't end up stirring things up more here, but I think there is bit of a cultural divide here. In US/EU people professionally disagree by prefacing with "yes, on the other hand perhaps..", "I see what you mean, but..." etc etc. to keep everyone's feathers smoothed. In Japan and Thailand, my experience has been that people would rarely even disagree with any statement, just nod approvingly. Other cultures go somewhat in the other direction, and expect you to be forthright/frank without verbal prophylactics.

Ayende Rahien
06/30/2011 03:02 PM by
Ayende Rahien

Peter, In Israel, we say: "You are wrong, and that is why"

tobi
06/30/2011 03:47 PM by
tobi

I prey to the gods that my career will never hit such a project. I am working on 50k of self-written lines of code and although this is not huge this is not small either. I still manage to get by with two C# projects and queries inside of my controllers. Have never found anything wrong with that approach yet.

Joe
06/30/2011 03:50 PM by
Joe

Other than https://github.com/ayende/RaccoonBlog/
Can you recommend any other sample applications that shows good architecture for non trivial applications?

peter
06/30/2011 03:50 PM by
peter

@Ayende I'll let you say that!

True story: my colleague in the pharmaceutical industry, in preparation for a business meeting in Japan emailed the Japanese team (in some big conglomerate like Hitachi) an excel spreadsheet with data to discuss in the upcoming meeting. He flew to Tokyo a month later and was put up in a hotel on their dime. In the meeting they basically hemmed and hawed and tried to make him realize without them actually saying it that they didn't want to proceed with his product. He pushed them until they mumbled some misgivings about certain lack of data in the spreadsheet. He then showed them that the data was there on a different "sheet", accessible by clicking on it's tab at the bottom. Their mouths dropped open and everything was cleared up ... all he had to do was come back to Japan for another meeting in a few months when they had looked at the data...

Ayende Rahien
06/30/2011 03:54 PM by
Ayende Rahien

Joe, Look at Alexandria and Effectus for other examples

Scott Rudy
07/01/2011 07:38 AM by
Scott Rudy

I can't say I agree with the general comments on the code sample (http://bit.ly/mSTS8V). I will be interested to see if feelings change if/when people read the book.

Hendry Luk
07/07/2011 12:21 AM by
Hendry Luk

I think you're missing the point of this guidance. The title clearly indicates that this is a reference implementation of THE "DDD architecture", which I believe has already been defined extensively in the blue-book. You can't just say you want to remove various components that you think you can do without, or to trim down all those layers, because then you will be missing some essential components involved in the formal blue-book DDD architecture. You see, the microsoft team do not invent their own new architecture and encourage people to follow it. They just simply take THE already-well-known blue-book architecture and show how you'd implement it using microsoft stack. It's not a guidance of how you build ANY KIND of applications. If anyone feels that this architecture is too complex for their requirement, it just simply means that DDD doesn't fit their projects. But when you do want to embrace DDD, this guidance shows you how, and i think it serves its purpose well. I see how some ms technologies can be fit to the picture in ways that I did not see before, and I think it's a good thing. Your review should really focus on specific implementation flaws that can be improve, rather than bashing the whole architecture itself, because following the DDD blue-book is the whole point of this guidance, and I can't see how any criticism on that front would be any useful for the authors

Hendry Luk
07/07/2011 12:24 AM by
Hendry Luk

Just to clarify when I said you can't remove some components defined in DDD. Of course you can. What I meant by that is you can't remove those things from a DDD reference-guide, because if would be like missing chapters

Ayende Rahien
07/07/2011 04:57 AM by
Ayende Rahien

Hendry, I have written multiple DDD apps. This isn't how you do it.

Hendry Luk
07/07/2011 05:09 AM by
Hendry Luk

DDD doesn't have to be done that way, but this guidanance uses the standard DDD architecture formally laid out by the blue-book. You got a point about its sheer complexity of it, but that seems to be a critisim that should be directed to the DDD architecture, not this particular implementation guidance

Hendry Luk
07/07/2011 05:14 AM by
Hendry Luk

A good example is the specification pattern, which I'm well aware you're not a big fan of, and indeed only few apps need it. But any DDD guidance won't be complete without covering specification pattern. At least it may give .net developers a pretty good idea of one way you can implement the pattern on microsoft stack should you ever need it

Ayende Rahien
07/07/2011 05:17 AM by
Ayende Rahien

Hendry, That is actually not the case. DDD was written about a decade ago, things change. You don't need specifications if you have Linq, you don't need to build repositories if you have an OR/M, etc. Those things were moved into the infrastructure, no longer required.

Serena Yeoh
08/01/2011 11:33 AM by
Serena Yeoh

Hi!

What do you guys think about the Layered Architecture Sample for .NET? (http://layersample.codeplex.com)

Regards, Serena

william simons
09/04/2011 09:45 PM by
william simons

I also wish you had taken a different approach to this and admitted you dislike ddd.
Why don't write your own book or series about this.?? Personally, I applaud microsoft for still believing in ddd!! I love ddd and oop princples should always be a part of .net and yes I love prism and unity dependency injection . I really hope that you really encourage and challenge developers to develop greater enterprise skills like oop techniques! That is what really make software enginerring fun Ayende, you could have 100 software engineers and everyone would have their opinion on how good software should be written. I am willing to listen however I may respectfully disagree with you, that's what makes it fun to debate!! Have a great Day!!

Comments have been closed on this topic.