Partial Demo Code - Neuparts.Shipping WCF Domain-Driven Service

Published 25 October 07 03:05 PM | Sam Gentile

I said, way back here, that I was working with another Neudesic Principal Consultant, Chad Thomas, on two WCF demo services/applications for my SOA with WCF and ESB talks. That talk, as many have noticed, spends a whole hour on Architectural, Domain-Driven and Software Patterns that I believe are neccessary to design and develop a quality WCF Service. The second hour of the talk is on WCF. I now will be giving you 1/2 of that code that has been used in the two New Jersey groups as well as the Chicago CNUG presentation. What was lacking was a real demo - I always showed crappy Hello WCF demos :). I wanted to show more and use some of my learnings but at the same time not take siz months to build a full domain-driven application.

The code reflects my current learnings. I have really Steve Eichert to thank, in the last 2 years of working together, having a very profound and deep influence on me with Domain-Driven Design and particuarly the Repository Pattern. We also learned a lot about how to organize complex Visual Studio solutions with lots of projects as well as reflecting the actual layered design. In that sense, we were heavily influenced by the directory structure generated and promoted by the Web Services Software Factory. We also used the Wilson O/RM Mapper.

Meanwhile, Chad was leading .NET development projects at JP Morgan Chase and also heavily using DDD, Business Entities, Repositories, TDD and Domain-Mapper. Chad has a lot of experience with the same areas I am interested in.

So, when Chad and I started doing this, we wanted to use all that we had learned and not make it "just another demo." Reemember, my stinky WCF demos were like Hello WCF! :) We wanted to reflect what we knew to be good patterns and practices in building a WCF Service. So to that end, the code:

  1. Uses the Layer Architecture pattern with a Service Layer Pattern, Business/Domain Layer and a Resource  Layer behind the WCF Service
  2. Service Adapter Pattern with Translator pattern to translate between Data Contracts (in the Service Interface layer) and Business Entity
  3. Practical example Domain layer using Evans Entities, Repositories, and Factories
  4. O/RM using NHibernate
  5. NUnit tests  (needs work)
  6. Visual Studio Solution, Project and Folder layout for a Services application

This is the work in progress. This is a working demo of an end-to-end WCF Shipping Service along with its Service Interface Layer, Business Entity Layer, NHibernate Repository and NUnit tests. This was used for the NJ User Groups, and Chicago.

  1. Requires directory C:\neudesic.Source for now
  2. You have to configure the config files for your database 
  3. Requires Visual Studio 2005
  4. Requires SQL Server 2005
  5. Requires .NET Framework 3

DISCLAIMER: This is incomplete. Not all unit tests are complete. There is no fancy packaging. We have full-time jobs on other stuff so this is NOT production code. There is no exception handling or logging. This is only 1/2 of the solution. The Ordering WCF system is coming. We will be putting all this on CodePlex for the community at which point we will involve the community in helping this go forward.

DOUBLE DISCLAIMER: This is NOT a DDD talk or demo. It is for a SOA with WCF talk and is a WCF demo. We wento to this extra effort because we believe it is the way that WCF services (and software) should be built. But it should not be viewed as a complete or conclusive illustration of a DDD application.

Get the current code here       CODEPLEX PROJECT now here

[tags: C#, F#, Domain Driven Design, NHibernate, O/RM, Indigo, WCF, Design Patterns, Windows Communication Foundation, Sam Gentile]

Comments

# Rogelio Morrell said on October 25, 2007 04:54 PM:

What is the differente between using nHibernateRepository and nHibernate from scratch (I mean, creating all the helper code)? Nice sample by the way Rogelio

# Sam Gentile said on October 25, 2007 06:09 PM:

Not much, Chad prefers to do it that way

Thanks for the nice comment and thanks for reading!

# eliteqz » Blog Archive » Partial Demo Code - Neuparts.Shipping WCF Domain-Driven Service said on October 25, 2007 06:11 PM:

Pingback from  eliteqz  » Blog Archive   » Partial Demo Code - Neuparts.Shipping WCF Domain-Driven Service

# Paul Gielens said on October 26, 2007 06:28 AM:

Sam, Chad thanks for the sample code. Well structured and easy to follow. One comment though, and please don’t take this the wrong way. I know that it’s hard to demonstrate DDD in demos while keeping them simple and small enough for a presentation. Where’s the domain model? Other then that, a good example of the MS-TLSA reference architecture.

# Sam Gentile said on October 26, 2007 11:14 AM:

Hi Paul,

Thanks for your kind comments. I didn't take it the wrong way especially since I view you as someone I highly respect in the DDD arena and I welcome your feedback.

It is a good question. One thing we wanted to do was demonstrate that DDD is not dogmatic. You still see all of the DDD patterns in here

Repository

Entity

Value Object

Bounded Context

We choose our own assembly organization by combine the best of DDD and Web Service Factory

cool?

This is DDD + SOA

We will have a CodePlex project up today with more documents. Thank you!!

# Chad Thomas said on October 26, 2007 11:52 AM:

@Rogelio Thanks for the feedback. Regarding the NHibernateRepository, it is primarily to simplify the API. You can read more on the case for NHibernateRepository from my friend and creator of NHibernateRepository here: http://arcware.net/archive/2006/11/07/NHibernateRepository.aspx

# Bil Simser said on October 26, 2007 02:40 PM:

Awesome sample, even if it is incomplete. A lot of great patterns and ideas here. A few questions though: 1. You create an NHibernate Repository directly in the InventoryRepository (several times). I've always injected an interface to that handles the actual implementation of my data access into my repositories so that I can be flexible in testing (I consider a Repository part of my domain layer, not infrastructure, but that might be wrong on my part). In your implemenation the items are flushed for sure, but is it flexible enough for testing? 2. It seems the code in the Shipping.Client is just test code. Shouldn't this just be in a unit test (and there is no client?) 3. Just a quick glance at the code and diagram, it seems to me the aggregate root is OrderHistory? Or am I reading it wrong.

# Paul Gielens said on October 26, 2007 04:35 PM:

I will have a look at the codeplex material later this weekend and get back to you.

# Sam Gentile said on October 26, 2007 08:54 PM:

@Bil

2. The code in Shipping.Client is NOT test code. It is the WCF client calling the WCF service. That is what the demo and the talk are all about

@Paul, Bil

A gentle reminder that is NOT a DDD talk or demo. It is a WCF talk and demo. We added all this because we believe it is the right way to build a service. We also added it to replace the HelloWorld WCF Service that I used to show instead. Please keep that in mind.

# Bil Simser said on October 26, 2007 09:46 PM:

Great Sam, thanks for the clarification and work. Looking forward to the CodePlex site.

# TrackBack said on October 27, 2007 12:00 AM:
# AX Dev Warehouse said on October 29, 2007 09:22 AM:

Resumo da semana - 29/10/2007

# Console.Write(this.Opinion) said on October 29, 2007 09:23 AM:

Resumo da semana - 29/10/2007

# Mike Griffin said on November 6, 2007 01:53 PM:

Our EntitySpaces architecture will generate your WFC proxies and is will serialize and deserialize into your true business objects, send only dirty rows and only dirty columns, very lightweight, works great. http://www.entityspaces.net/blog/2007/07/28/EntitySpacesWebServicesExampleApplicationWithWCFImplications.aspx See the "The XmlProxy Webservice (and WCF)" section. EntitySpaces Persistence Layer and Business Objects for Microsoft .NET http://www.entityspaces.net

# re: Partial Demo Code - Neuparts.Shipping WCF Domain-Driven Service said on December 5, 2007 05:17 PM:

Pingback from re: Partial Demo Code - Neuparts.Shipping WCF Domain-Driven Service

# Fuzze said on December 6, 2007 06:15 AM:

Hi !

Thanx - for a great demo

I know the demo's not about patterns, but is that really an Adaptor? Shouldn't it be called Factory. Its creating a datacontract from an entity. Isn't an adaptor similar to SomeClass ( IAdaptable someOtherClassToWrap)..

if not please explain, so I can clear my confusion.

Once again

Thanx - for a great demo

# Sam Gentile said on December 6, 2007 08:45 AM:

Hi Fuzze,

Thanks for your nice comments and interest. If you are speaking about the Service Adapter, I am using the same name that the Patterns and Practices people use as well as what we did at Algo. It is not really responsible for the creation. It is responsible for the adapting of the service layer data contract representation to the business layer representation (Entities). It uses a Translator pattern to do that. I could have delegating the creation of the classes to a factory but I haven't got to that yet. Make sense?

# Fuzze said on December 6, 2007 09:51 AM:

Hi !

Thanx Sam.. to asnswer your question - Makes Sense ?

Ummm not really :)

As far as I can see ServiceAdapter merely implements IOrder.

**Adaptor def. as found on doFactory.com: Convert the interface of a class into another interface clients expect. Adapter lets classes work together that couldn't otherwise because of incompatible interfaces. **

It's not very obvious :-) BUT I do see it now :)

took awhile.. :)

Thanx !!

# Fuzze said on December 7, 2007 06:43 AM:

HI! I'm back :-)

Question about translation layer, I want to know if instead of the translation / mapping class, is the following possible ....

In my Domain(project) Domain.Account which implements Domain.IAccount. Then in the service(project) Service.AccountDataContract also implements Domain.IAccount but decorates it with the DataMemeber stuff...

In the WCFService implementation I get a Service.AccountDataContract passed into the method .  So Instead of the translation step , could I do this...

Domain.Account account = (Domain.Account)(InputMessage_Service.AccountDataContract_Object as Domain.IAccount);  

????

I really hope that question makes sense !!!

Thanx

Leave a Comment

(required) 
(required) 
(optional)
(required) 

This Blog

News

    The content of this site are my own personal opinions and do not represent my employer's view in anyway.

    Profile for SamGentile

MVP

Blog Information Profile for SamGentile

Syndication