[Link List]Microsoft Application Architecture Guide, 2nd Edition is now complete (Ebook, Print)


Microsoft has released a final version of its book “Microsoft Application Architecture Guide, 2nd Edition”.
The book is described as:

imageThis guide is available online here in the MSDN Library and will be available in the Fall of 2009 as a Microsoft Press book, ISBN# 9780735627109, that you can purchase through local and online booksellers.

The guide is intended to help developers and solution architects design and build effective, high quality applications using the Microsoft platform and the .NET Framework more quickly and with less risk; it provides guidance for using architecture principles, design principles, and patterns that are tried and trusted. The guidance is presented in sections that correspond to major architecture and design focus points. It is designed to be used as a reference resource or to be read from beginning to end.

The guide helps you to:

  • Understand the underlying architecture and design principles and patterns for developing successful solutions on the Microsoft platform and the .NET Framework.
  • Identify appropriate strategies and design patterns that will help you design your solution’s layers, components, and services.
  • Identify and address the key engineering decision points for your solution.
  • Identify and address the key quality attributes and crosscutting concerns for your solution.
  • Create a candidate baseline architecture for your solution.
  • Choose the right technologies for your solution.
  • Identify patterns & practices solution assets and further guidance that will help you to implement your solution.

More information about the book in this blog post:


The book is:

Available for online reading at:


Available for free download (PDF Format) at:


Available in print (to buy hard copy) from Amazon at:


Have fun reading,

On the arrival of Mr. Adam Meligy

Image007000 - Copy

Today (technically yesterday, since it’s 3:26 AM already while I’m starting this), Mr. Adam Mohamed Meligy finally arrived home, after staying 9.5 days in nursery. This –dear audience- given Mr. Adam arrived to our world only in October 5, 2009, a date that the entire world will (sooner or later) always remember!

Mr. Adam is now taking a personal cover, pretending to be a normal baby, while he is pretty professional, he cannot sometimes hide his special natures, being relatively quiet compared to normal babies, and highly responsive to touches and (believe it or not) spoken notes/requests.

These are things that the world will remember once Mr. Adam finishes his first big achievement in the field he will take up for living (God Willing). Some other small details matter more to the family, both his grandparents –for example- note him as their first grandchild. I –personally- recognize him as my extra chance in life! If I fail to manage to be another Anders Hejlsberg/Martin Fowler, Scott Guthrie/Brad Abrams, or Scott Hanselman/Rob Conery/Phil Haack (still trying), Mr. Adam has a bigger chance; else wise, he’ll be digging his road as a notable figure in some different field (God Willing).

I feel that I was blessed with not just two more legs and hands, one more tongue and a couple of stronger eyes, extra more years to live, but also with an extra brain and superpowers. You can always upgrade your thinking methodologies, even reinvent the way you think completely, but you are always limited to your physical brain constraints that -although can be always stretched more and more- have their limits. Now I have an extra brain that can do pair thinking with me and reinvent the way things happen by the experiences he will be having on his own (God Willing).

So, this is to log that Mr. Adam (temporarily until he decides to replace that with “Eng.”, “Dr.”, and/or “Prof.”) has just finished implementing phase zero,  coming to existence!

Few More Facts About Mr. Adam’s Arrival

  • The exact time of arrival to world is October 5, 2009, 10:30 AM Abu Dhabi Time, that’s 8:30 AM Cairo Local Time (CLT), 6:30 GMT.
  • Although born in Kornesh Hospital, Abu Dhabi, UAE, Mr. Adam holds the Egyptian nationality, just like his parents. He also inherits the Islam religion, which he will be (God Willing) discussed about as soon as starts making conversations, so that he practices it for the sake of belief, not inheritance!
  • Mr. Adam reached our world after hiding in a secret cafe for slightly less than 35 weeks, reaching our world at the weight of 2.25 Kg.
  • Mr. Adam has his email, Facebook and twitter accounts created on the day of arrival and moderated by parents. Soon (God Willing) he will be running those himself, and creating his own LinkedIn account on his own once he finishes his first school and starts a professional expert career simultaneously.
  • Mr. Adam has come with the message to make the world a a better place to live for humans, not to dominate the entire world ;-).
  • Since arrival, the protocol requires using the prefix “Mr.” when mentioning Mr. Adam’s name in conversations. Only tweets/categories, etc… are allowed exceptions due to technical/official nature. This prefix is temporary as per the relevant note above.

On behalf of the family, I congratulate the world on having Mr. Adam with us. I’ll be following up with his significant news until he starts blogging (hopefully soon, God Willing).

Using EQUATEC FREE .NET Profiler with ASP.NET Applications

This was originally an email I sent to .NET team in my company, then decided to share as a blog post.

The problem:

  • Let’s say you have a complex application, and this application (or part of it) runs very slowly. No bug s in results, no errors or exceptions, but it just so slow! Now you want to know which part of your code is the reason, which method(s) you need to go and modify., which methods take so long to execute or consume so much memory/CPU. How would you know that?
  • Let’s say you want to improve the performance of your application in general (say add caching or such), so, you want to identify which parts of your code deserve your attention and will really make difference (so that you don’t waste your time on optimizing something that will not have big effect in performance), for  example, you might want to identify which methods are called more than others from different parts of your code. How would you do that?

How to solve it, or, what is a profiler (v. short):

It is an application that you can run along with your own program. It’ll track all method calls and how any method call other method and most importantly how long each method call will take, and how it consumes resources.


There are many .NET profilers out there.


So, what about EQATEC:

Quoting from homepage:

Spot slow code

Are you a .NET developer? Would you like your application to run faster? Then use our free profiler to spot you app’s slow code.

Point and go

No source code changes are needed. Just point the profiler to your app, run the modified code, and get a visual report.

Speedup any .NET app

As the only code profiler in the world, our profiler can even handle Compact Framework applications.




clip_image001 C#

clip_image001[1] VB.NET

clip_image001[2] Managed C++

clip_image001[3] F#

clip_image002 C or C++

clip_image002[1] Java

clip_image001[4] .NET 3.5

clip_image001[5] .NET 3.0

clip_image001[6] .NET 2.0

clip_image001[7] .NET CF 3.5

clip_image001[8] .NET CF 2.0

clip_image002[2] .NET 1.1

clip_image001[9] WinXP, Vista

clip_image001[10] Windows Mobile

clip_image001[11] Windows CE

clip_image001[12] XP embedded

clip_image001[13] PocketPC, PDA

clip_image002[3] Linux

To use it with ASP.NET application, all you need to is:

  • to put the path of the “bin” folder of your website as “App Path” (no need for source code or debug files), then it shows a list of all assemblies in it so you choose the DLL(s) you want to profile, and click “Build” at the right corner of the screen:
  • Click “Open output folder” on the bottom left corner, copy the DLLs from there to your website “bin” folder
    • Alternatively you can click “App Options” and set the output folder to “$(AppDir)” so that the generated files replace the old one
    • You need to repeat these previous steps if you build the website again using Visual Studio
  • run the website and start using it for a while
  • go to EQUATEC “Run” tab and click “Take Snapshot
  • go to the “View” tab and start reading the results

It might be important also to spot the limitations:

Known limitations

This is a list of known limitations and problems in version 2.0.

  • Blocking methods, such as Read(), will be counted as the total time, including the time the thread spends being descheduled and waiting for the call to complete. For now, you will have to recognize and judge situations like this manually.
  • No debug information is available for the profiled assemblies. It means that you cannot debug the profiled versions – but you would probably not like to do that, anyway.
  • No Visual Studio integration yet. We are looking into providing an add-in that will make it even easier to enable profiling your solution’s assembly files.
  • No full method signature is displayed yet. So if you have several overloaded methods by the same name, or use generic methods, you cannot easily distinguish them as their signature (the method’s parameter list) is not displayed anywhere.
  • Only defined methods are currently profiled, not referenced ones. So all the methods that your application itself defines will be profiled, but not System.* etc.

I hope this is useful for some of you as it was a real saver at times to me. Thank you very much!

Videos from NDC 2009: SOLID Principles, Legacy Code, WCF, Software Design,…

Here’s another email from the internal mailing list of Injazat .NET Ninjas (Ninjazat, AKA  as we call ourselves), that I’m sharing with blog readers as well.

Just a place holder, until I move one of my 18 (just discovered the number now – terrifying!) drafts in my Windows Live Writer into a published post, or delete them all!

Subject: [Learning] Some very interesting videos

Some videos from NDC 2009 event (Norwegian Developers Conference 2009) – about software design and related issues:

· NDC Video – Robert Martin – S.O.L.I.D Principles of OO class design

· NDC Video – Robert Martin – Craftsmanship and Ethics

· NDC Video – Robert Martin – Component Principles

· NDC Video – Robert Martin – Clean Code III – Functions

· NDC Video – Michael Feathers – Working Effectively with Legacy Code

· NDC Video – Jeremy D. Miller – Convention Over Configuration

· NDC Video – Michael Feathers – Seven Blind Alleys in Software Design

· NDC Video – Ted Neward – WCF Patterns

· NDC Video: Michael Feathers – Design Sense

For the complete list of videos from this event check videos from:

· Day 1

· Day 2

· Day 3

My favorite topics are (recommendations):

· NDC Video – Robert Martin – S.O.L.I.D Principles of OO class design

· NDC Video – Michael Feathers – Working Effectively with Legacy Code

Of course the other topics are interesting as well.



See you all in dotNETwork May 09 Gathering in Egypt, Lesser known .NET Enterprise Patterns & Practices




There was a sudden last-minutes issue with the transportation / flights configuration that prevented me from making it to Cairo. I’ll be unfortunately missing out this event. M. Smay my friend will be a great backup with all the additional details he has to provide about his session content as well as an open session for the convenience of all of you.

Sorry for missing out. I had to. I’m working with dotNETwork to re-organize my session as part of June 2009 gathering, but this is gonna be another story!


Most of you already know I have moved recently from Cairo to Abu Dhabi. What only a selected set of you are aware of, is that I am still having my heart all set for the developer community in Egypt and still communicating with many of them via Twitter; not only that developers in Abu Dhabi are not into spending time in gatherings or anything than doing work and surviving, but also because I have made the only long lasting and fulfilling friends relationships with the key persons that I see in the different communities, especially my old friends from Microsoft MDC and ArabTeam2000, Demo Day attendees (who still talk to me since 2007), and – of course – dotNETwork, admins, speakers, and participants (who are much more than just attendees).

Fridays City Stars 23rd of May 10:00 AM – 01:00 PM

This Saturday isA I’ll be giving a session that relates to one of my beloved topics in development. Here is the information of the session:

Session Title

Lesser known .NET Enterprise Patterns & Practices

Tag Line

Is your mind ready? Booting up journey in enterprise patterns & practices in .NET

Session Summary

Through an illustration and a thoughtful discussion we are going to see how to go with our applications to the next level, leveraging ease of maintenance, integration points, and scalability out of the box; showing sample enterprise patterns and best practices that are very popular in many development platforms but are rarely used or even known for typical .NET developers

The session will be like April’s session in Fridays City Stars, Nasr City. If you want to know what that is, this is because the Canadian University in Egypt  has stopped all activities in Saturday temporarily for reducing cost; you know, the crisis!


Agenda, date and location

  • Lesser known .NET Enterprise Patterns & Practices
    by Mohamed Meligy – Information Analyst, .NET Technologies – (Injazat Data Systems, Abu Dhabi)

  • A lap around Visual Studio 2010
    by Mohamed Samy – Technical Architect (iSource Egypt)

Fridays City Stars 23rd of May 10:00 AM – 01:00 PM


Have you noticed something? Yes, my closest friend and one of the most lasting / oldest friend in this life, and in the field of course, Mohamed Samy, will be giving a session the same day. HE is such a true guru, and I fear everything ‘m going to say may look very pale compared to what he has to say about VS 2010.


By the way, the attendance will require you to only pay 19 EGP or so– for a sandwich or meal that YOU eat (they have discounts for attendees). This is the host requirement and dotNETwork has NOTHING to do with it. After all, the only available host is now a commercial place. If you can help dotNETwork host the sessions in a completely free place, please contact anyone from dotNETwork and help get that done. PLEASE.

Anyway, I think 20 EGP for something YOU get within the day is not very little but not much also. I saw guys paying the same to the cafe near the University when it was hosted there.


Please be there. I know everybody was too busy to do right publicity of this event, and I myself am writing this very shortly before the event day, but, I’ll not be able to come back to Egypt even every few months, so, this time is very rare for me. Please let me meet the most of you who can make it. This is a personal request, to my true friends. period


Related Sites


dotNETwork 10th: Architecture Speaking for Itself (DI / AOP)

As ever, there’s

The usual intro …

The .NETwork day for December that took place this Saturday as the 10th group gathering/event was pretty much worth being the day that makes a whole year for .NETwork group, which started December 2007. The day was pretty much different than usual, maybe similar to the very first gathering in organization, and some other days in topic, but the style and taste was a bit different. Pretty much concentrated, although on a variety of topics.

The day was just a couple of sessions. Love it or hate it, no parallelism there. The sessions were given by a single speaker, Omar Besiso, a half Egyptian senior Architect living in Australia, a consultant, Tech Ed presenter, book editor and reviewer – a very great guy as I’ll explain later :).

Actually I really enjoyed the first session. Really want to attend / give many similar sessions in the future.


I have not been very honest while writing this! Since I have a similar interest in the topics discussed during the session, I have written some parts of the post that were not said during the presentation the same way,a and provided some examples and such that represent my own understanding which may or may not be the same as Omar’s.


Lets give it a strong start :-) …

… On Architecture

“Who here is an architect, or works as an architect?”

Having a very quick meal just before entering getting us exactly a minute late (me and Mohamed Samy, my dear friend, without getting lost in the way this time), and before we finish plugging in our laptops and firing OneNote, we were hit by the question as the true start of the session.

Of course I and M. Samy stood for it. This led us to talking about what an architect does exactly. the short answer is “everything”. He designs applications, interfacing between those applications. He meets customer. He still writes code and maybe Prototype or Proof of Concept. But there are types of software architects:

  • Solution Architect: Close to the team decided to work on the solution, performs architecture for a specific solution.
  • Enterprise Architect: This is the one that does everything communications to the office boy and to the CEO. In other words, he handles the solution from the very beginning of whether to have a single solution or series of connected ones.

That talk was before Omar introduces his work-in-progress book “Reactive Programming & Domain Driven Design”, speaking on himself as a “Not technologist.,, but very low Java IQ” (It was interesting to know such exists!). This means that he has no special feeling about any specific .NET technology, or a language, and this is very important, to be able to mentally choose the right technology for the right situation (he made another statement that he uses SharePoint whenever the budget allows, plain ASP.NET only otherwise, which is another interesting topic). However, this is all on top of the .NET platform, as “The technology-Independent architecture that we heard of in the 90s is no longer a fact”.

… On Architecture Myths and Data Driven Architecture

Those are the things most people believe in and do, while are no longer relevant to today’s and future architecture.

  • Myth No.1: 3 Tier Architecture
    • You know this  UI –> Business -> Data thingy!
    • Of course we today know we need other layers
    • How about logging, where does it fit here. Object Pooling, etc…
  • Myth No.2: N Tier Architecture
    • There are so many styles, but usually that’s what it ends to: UI -> External Service –> Business –> Internal Service –> Data
    • The point is, as in the next myth, that is all goes in circles around data.
  • Myth No.3: Data Driven Architecture
    • Bring the DB, fire up the DAL generator, build some “business” that just calls this and bake some UI for it.
    • The argument here was: what if you do not have exactly a database. How about things like Office or Photoshop or so.
    • “We use CodeSmith/.NETTiers as our architecture” What a statement. Is code generation exactly an architecture?
  • Myth No.4: Architecture and design are an overhead
    • Architecture is like an investment. Omar quotes: “If every investment is an overhead, it’s time to sell your assets”. To be fair, I mention he has been working with big projects of hundreds of developers still in one project.
    • The point is about maintenance and updates that takes most of the real time of a project. It’s about responding to change, and the time it takes to actually do respond to that change.
      • For example, for an interest rate value to change, this may be as easy in your design as changing a configuration value, but, how about changing the way this interest rate value is used or the interest way of calculation?
    • Side Arguments:
      • A bad architecture can cost an entire rewrite of the whole solution from scratch not even parts of it. Sometimes if things go bad such a decision is the right one to have.
      • No university on earth teaches the “right” software engineering! Even MIT has hundreds of methodologies, that you don;t know which to follow.
      • “Do not let a software engineer build your house”, you cannot afford a bug or rebuild in there ;).

Clearly, Omar is against the Database-First approach. I heard the same things many time on ALT.NET threads, and it takes many posts to talk about without much benefit, but anyway, Omar’s main argument is that you heart your model (say the classes you use to represent types of business objects, like “Product”, “Customer”, etc) so much when it is just a representation of your database row.

If you change a column in your database for whatever database performance reason, and the model class is a serializable one, and then you de-serialize an objec serialized before change. How will you manage that? (I actually had the same exact situation before, with an object serialized to be persisted in Windows Workflow and de-serialized after months where the class changed due to coupling to the DB).

… On General Guidance

Here came some general notes on achieving in software. Software NEEDS to be (just as in those old computer science books):

  • Highly Cohesive
  • Loosely Coupled
  • Hardware Independent
    • Not that it works on PC and Mac :)
    • But that it (as much as possible) works on 1-processor single machine to a farm or cloud of servers with so many logical and physical processors in them.
  • Reliable
  • Performing
    • Concepts have changed here. People now no longer apply a rule like “reflection is too expensive to use in our applications” (and many great things we see today use reflection heavily in their core)
    • Odd enough but works: In many situations, when you have issues with performance, you just put more RAM (Hardware in general) into it until later you fix/re-factor. Hardware is cheaper than programmers.
  • Maintainable
    • This is what today’s designs and patterns focus on most.

In general, software is developed to fulfill certain needs. It need to be architected and planned to fulfill those needs. Software needs to be:

  1. Envisioned
  2. Planned
  3. Executed
  4. Adapted

… On Layering With Recent Architecture

Then Omar went on talking about architecture in a bit weird way. He went through architecture of the future, and afterwards, of today.

Here’s how he sees architecture of the future:

  • Subsequent of the past
    • New Tools, Old Patterns
      • Design patterns have been there for years.
      • The best way to describe Service Oriented Architecture (SOA) is in terms of component oriented design, the same concepts of the old COM+.
      • Service Locator and Dependency Injection are just glorified factory patterns.
  • Destruction of religious discussions
    • Religious Discussions
      • Dynamic Queries vs Stored Procedures
      • C# vs VB
      • Plain ASP.NET vs SharePoint
      • …..
    • As mentioned before, do not special feelings about a certain technology.

To reach this, that’s how an “Architecture of the Present” consists of for Omar:

  • Consumer
    • ASP.NET, WPF, …
      • Note that a WCF service that depends on another service or solution is also a consumer of that
    • Needs to talk to black box that has the engine
      • Knows nothing about implementation, just a contract
      • Normally you should be easily swapping implementations (contents of the black box) while keeping the interface(AKA, the box).
      • Black box is only DLLs, with no tech, not It’s not SharePoint not anything, the only dependency for it is .NET framework.
        • I asked Omar how do you test and mock work that you do in MOSS (SharePoint), he said that it’s usually just dump code that calls WCF services that are actually the front faces of all the real operations.
  • Domain
    • Entities and Services
      • Entities are the model, again, the “Product”, “Customer”, etc. To explain I tell you they do NOT contain anything except their own knowledge. No persistence or such.
      • Service are:
        • Data Services (“UpdateCustomerRecord”)
        • Business Services (“CalculateDailyReport”)
  • Core
    • The very basic entities and interfaces for the services
    • The contracts live here, the implementation goes to the domain.
    • Say this is a VS Class Library Project. Then this will be the only Project that does NOT depend on other Projects in the Solution, and mostly all other Projects will be depending on it.
  • Aspects
    • Cross Cutting Concerns, the things you perform/need for almost every solution
      • Validation
      • Security
      • Logging
    • They should be implemented in a way that provides consistency path. So that developers are not confused when writing it.
    • Omar says those should be injected. We’ll see how next.
  • Only now after defining those, Omar tends to create the database.
  • Then comes the actual service implementation.
    • He uses dependency injection to makes the consumer just calls the domain via the contracts (interfaces) to and then the implementation gets injected.
    • For Aspects, he uses Aspect Oriented Programming (AOP) / Policy Injection to save the developer from writing those for every method / property.

… On Dependency Injection

Dependency is about interface oriented programming:

  • The Core will have its IService interface
  • The domain will have its ServiceImplementation class that implements the interfacen.
  • The consumer will NOT reference the domain directly. It’ll call “something” called Dependency Container that returns an instance of that interface.
  • The container is then configured to return an instance of ServiceImplementation whenever it’s asked for an IService.
  • Normally you wouldn’t have interfaces for entities (just the services).
    • So, you might not have IProduct interface, but most likely you have an IProductRepository (a data service for Product).

Think of contracts for your day-to-day services. Say a Plane Ticket. This is an API, an interface. It has Date, class of food provided, flight no., etc…, but it knows nothing about the exact physical plane that will hold this number, how it works, or the name of its captain, because this is all implementation detail.

This guarantees ease of changing the implementation (say replacing the plane itself). Services need to be designed by the architect. Of course they all reference the core (which holds the contracts), hence you can easily have other service implementations later.Note that the entities implementations are just testable unit/implementations on their own with no special dependency/reference

Again, the cores references nothing,and most other layers reference it. That’s why internal dependencies need to be defined. This is what products like NDepend provide today and what VS 2010 is going to have built-in.

… … The Service Locator

This is just a factory. It’s job is to locate the service implementation (I’d ask you to imagine a GetProductService function with return of type an IProductService as a service locator). That’s how the consumer never talks to the domain. It calls a Service Locator to get a reference to the service without knowing anything about the service except its interface that lives in the core.

There’re two ways the locator can locate and return the desired service. The service type may be written down in some configuration file and it uses reflection or so to get it, or it can perform some other code logic to get the service (which can be as easy as loading some service assembly and getting a specific class from it).

There is no standard for implementing the locators. You may want to provide a singleton object (have a single ProductService and return it every time an IProductService is requested rather than creating a new object for every call). You may want to cache the object for a certain period.So, implementation does differ.

… … The Dependency Injection

What dependency injection adds to implementing a service is:

  • Standard
    • You have a certain library that you call to get the dependency (service). You configure this library for your specific needs.
  • Turns Service Locator into Glorified Smart Factory
    • It can do more functionality, and it has been tried.
  • It can crate an entire chain of objects, not just one.
    • What if you have (and this is not an accurate example or best-to-do) an IOrderService that has one property of type IShippingService, and you want to create the order service and the dependencies of Order service itself. A dependency container library should provide you with a way to define in the same place what order service to use, and what shipping service to use with this specific order service.
  • There’re main libraries for it
    • Castle (Windsor)
    • Structure Map
    • Spring.NET
    • Enterprise Library (Unity)
  • The style is simple, you have a component (any kind of consumer code), it calls a configured dependency container, and this container returns a ready-to-use instance.

To demonstrate this, Omar presented a demo of an IProcessor interface with only a single method: ProcessMessage and a single property SubProcessor of type ISubProcessor, ISubProcessor also has a single method ProcessToConsole. Each of the methods takes a single parameter “”Message” to process.

Now the service factory is easy to create. Using Unity, that’s just a few lines of configuration copied from documentation. The implementation is pretty easy too. Just write the classes Implementation1,Implementation2 that indicate (by simple writing to Console) they were created and called and then pass the message to the sub processors, SubImplementation1, SubImplementation2 that also just indicate they were created and called.

The console program that acts as a consumer was also easy. It has some code like:

IProcessor processor = ServiceFactory.GetProcessor();

processor.ProcessMessage(“The message”);

So, hrere you seethe consumer just talks to the service locator. In the app.config file we tell what implementation to call when asked for IProcessor and when defining that tell it also what to return for ISubPorocessor. To demonstrate, Omar showed calling Implementation1 with SubImplementation2, Implementation2 with SubImplementation2, and even showed that Implementation1 with SubImplementation2 would just work. And run this on the console to see it actually did work.

… On Policy Injection

As mentioned earlier, the policy injection is a pattern that handles cross cutting concerns, the normal things in all projects. Exception Handling, Logging, and Exception Handling would make it for great examples. They’re things shat we shouldn’t be writing code for them everyday!

The way you do this is by using a global handlers that you inject them (say as you do in dependency injection or by putting Attributes on the thing you want to inject into, which is [in OVERLY simplified manner] Aspect Oriented Oriented Programming). Then have then create events that you implement handlers for. Those handlers become the single place to write your policy code (the logging, exception handling, authorization check, etc..).

There are of course frameworks that help you doing this:

  • Castle (Windsor)
  • PostSharp (Code Contracts in .NET 4)
  • Enterprise Library (Policy Injection Block)

The idea of using is similar. The consumer creates object from a factory, then this instance gets a proxy class created around it (similar to the proxy class that gets created when you have a plain old ASMX web service, anyway, it depending on the library and whether it works in runtime or compile time) around the object, and have events in every property/method in that proxy, then others can subscribe to those events later to inject their policies.

To illustrate, Omar presented another demo. He had a Calculator class (that of course implements an ICalculator) with one method SubtractTwo(number) that just does as its name says (subtract 2 from the given parameter), and showed how to use the Enterprise Library Policy Injection to put a logging handler for it that was set in conifg for all objects of type ICalculator. That’s how the policy is applied to all objects from configuration while the consumer got the ICalculator object itself normally by asking a service factory to create it.

So, as per Omar, that’s how you would do it (like other parts in the post, made longer to illustrate more):

  • Configure what implementation to attach for the specified contract
  • Configure what aspects to to have along with entities and services that implement this contract
  • Create the the actual implementation of the attached service
  • Wrap it with the chosen aspects.

Omar also showed another demo. A real life code from a real customer (one of the big customers he has been working with). We saw the –now– normal stuff, the core that references no one (with interfaces, aggregates, and service contracts in it) , the services either business (which We things like SomethingEngine or SomethingManager,…), or data (which were called Repositories – as usual in similar architectures).

… On Summing up

On summing up,Omer emphasized:

  • Do not code logging (and such) over and over again
  • Watch for performance, moderately
  • Go for standards
    • Use Standard Frameworks, not no name ones (DISCLAIMER, that’s Omer speaking).
    • Standardize your own frameworks.

I have the feeling that I didn’t include everything here, especially some side talks that were worth noting (some are noted). It was a great session with some discussions that are rarely there except in very small groups. Again, I really want to bring similar discussions, either as a speaker or an attendee.

Then came the open sesion …

Well, This one was an open session. I haven’t seen a “bad” open session in Egypt, but also never saw one that would meet my standards for “Successful”, “effective” or such …

There wasn’t much audience this time (Which is really funny and always happened! Seeing that a vast majority of the attendees are students, when the sessions are prepared to meet this level, the audience that attends happens to include many high rank developers. As you may have guessed, when the sessions are prepared to meet this advanced level …. Yeah, only the junior ones are there. This is another post on its own!).

This time the audience was ready for the session but much fewer than it should have. The open talk session didn’t have much talk then more than a demo that shows Tech ED domo on how to use the MS Reporting Services 2008 Report Viewer to create a report from scratch, publish it to your server, and export it to MS Word n less than 5 minutes. Not something that would impress me personally when it has the “less than 5 minutes” in it and Omar himself said a simple report in reality would take around half an hour to design.

The other talks were all like “”What do you think about using the X… technology in Y…. situations”. It was limited to one-hour session anyway due to accidently tight buses seclude.

Some things that are good for example are mentioning the models of doing software in/outside the cloud (topic brought by Mohamed Samy).Omar said those are the common themes:

  • I build software and build data
  • The two at Microsoft (or whatever provider)
  • Data is here but the software is by another provider
  • Data by vendor and he’s liable to it
    • By looking at the terms and statements of Windows Azure, Omar says he found nothing that expresses liability from Microsoft’s side.

Also, when someone asked him whether to use WPF or Win Forms for desktop “Business” applications. He said he uses WPF for all his applications, for business applications he has a WPF theme that looks just like Win Forms. He explains why he does it this way:

  • WPF works directly on the GPU.
  • XAML is a great language, same like HTML but without all the browsers headache and even better syntax.
  • Basically a business application does not have complex UI requirements, but, if some are requested, a WPF application is ready.

He also mentioned the best way to learn .NET is to open reflector, browse the namespaces and see the code for anything whose name grabs your attention. An example is how Serializable attribute is implemented, it’s just an enum :). another example is how to implement an Object Pool. So that for example whenever an object is requested, no more than say 5 instances are created and reused in later requests. Before you think about the implementation, it’s just there in the BCL,in System.EnterpriseServices.ObjectPool. Just have an ObjectPool with Max set to 5 and you are done with it :) :).

It was a really great day. Thanks a lot, Omar.


In Search For Agile Domain Driven Design … Hopefully Part 1 of N

The Useless Introduction You Used To :)

This post has taken so long to be started in writing. I’ve been busy with many events in my life lately. Suffering from frequent limited internet access lately, and, all this moving between companies thing has been eating me. And yes, I admit, I’ have been as tired and more honestly lazy as you expected me to be!

Hey, there’s a little warning. This post is not exactly for my usual audience. I’m sorry, but introducing Domain Driven Design is not one of the goals for this post. There’re many interesting resources and books (even FREE: InfoQ, Domain Driven Design Quickly) on the topic. However, if you leave me a comment telling me to make a write-up on the topic, of course I will :) :).

One more thing. Another reason I’m working on this is that I’m preparing for an internal session here in Raya about Practical Lightweight Domain Driven Design. This session is truly internal yet. It should be recorded though but I’m not sure whether it’ll be possible to publish the videos (Yeah, I will see how we can have our public sessions of possible sure!). If you have a user group and would like me to give this session in a group meeting, I’ll be glad to do.

Introduction Still: The Messages, The ORM

This post was originally a couple of messages I’ve sent recently to the ALT.NET Yahoo Group. In which I discuss using Domain Driven Design with an ORM, more specifically, my favorite ORM, LLBLGen.

Quoting from the first message:

For now, we’re going towards LLBLGen Pro 2.6 for DAL generation and such (using Self-Serving mode probably). Yes, we’re going for database first design, and not using NHibrernate. I’m hoping that we can keep those two issues for other threads :).

Right now, I’m going for other Domain Driven practices. I want to make sure using POCO classes is worth it, and then see how to have those in LLBLGen (which -LLBLGen main template- is in its internal not much different design than Active Record, which in many times is handy, it’s VERY rare t change DAL when one fits different DB providers with good performance), and what are common patterns to do Domain Driven Design at all when having LLBLGen as DAL (if it makes any difference – again: and if effort to make it encapsulated enough to make no difference is worth it).

Making this choice alone is worth its own article. Maybe should title it “In Search For The Perfect ORM” as well :-D.

UPDATE: Frans Bouma has a nice write-up about what is an ORM and different types on an ORM. It’s quite old (2004), but the concepts themselves are still valid.

My original question was:

So, is anybody here doing DDD and uses LLBLGen as DAL generator ?How does the experience look like ? What are common practices across all projects and what have been pitfalls ? etc… These are the kinds of questions I’d love to see somebody here with something to share about.

Domain Driven Design At Work

This is not really an LLBLGen issue. It is questioning the Domain Driven Design productivity itself. I like DDD. I see it as the natural next step after 3-tier deisgn. This whole separation of concerns, models, repositories, factories, infrastructure, and services paradigm just fits my mentality and view of how the world looks like. However, not all the practices in DDD are similar in terms of return of investment, the customer business value that Agile emphasizes. The trick is to know which are and which aren’t, and how to do the balance.

In the second message, I go through an example of typical usage for DDD that has tried just a little bit to be lightweight in some areas but not others, and my own overview about what needs improvement:


I’ve been on a project that leverages DDD once before myself. The project has been frozen for a while for other priorities, etc…Maybe I start with my own take on the subject!!
We’ve been using the “Adapter” model. I thought it was for seeking some sort of more control/flexibility. Reading Fran Bouma’s blog (http://weblogs.asp.net/fbouma, the creator of LLBLGen), I see how he’s so much of an “Entity Design” guy. Well, makes sense, he owns the best entity design I’ve seen so far having considered EF and CSLA.
Clearly he sees the “Self Servicing” as the core for entity design rather than model design. You know, the “entity.Save();” style. This makes me have two thoughts at a time actually. 1- That “Adapter” model is the right choice for DDD (I’ll get to that just below), 2- That maybe DDD fully is not what I really want (the entity Self Servicing style is so powerful. It has saved my day so many times before).
Looking at the project I’ve been working on, We had something like those namespaces / VS projects (and others … ):
Company.Project.Adt (for models that may be reused in other projects, like Language, Currency, …)
Company.Project.Model (for project business domain specific models)
Company.Project.Data (for LLBLGen stuff, we have also “DataDBSpecific” and such related to Adapter mode)
Company.Project.Repositories (have interfaces and implementations for repositories, let’s put aside why the two in one project for now)
A repository load method could probably look like:
  Category Repository:

Or for internal use:
  Shop Repository:


What I want to highlight here is the “include…”, “load…” parameters. I’m not sure whether this is the best way to do it.
Also, what really hits me is the mapping. You know, from LLBLGen entities to our domain models. We have been doing this in factories which live in the Repository space. Each factory had methods similar to this:


Regardless of the “public” access modifier (this is all very well hidden behind a service layer, but let’s put the whole issue aside as well), the idea of having to go through all the mapping has been just a boring ugly task, that has been there for long.
To be honest, we didn’t get so much benefit of it. It should have good promises, but how good compared to the cost of implementing them for complex object graphs ? That is the question!
Things got just worse when we wanted to implement our service layer. That’s a service in the classic sense of “web” service layer (REST), we wanted to created DTOs that can correspond to XML and JSON responses of our choice, and again, we had to do the mapping from and to the domain models and DTOs. Want more ? The DTOs wouldn’t convert to XML strings automatically (to JSON it would), we had to have another mapping layer from and to the DTOs and the actual XML.
Of course we had much time defining XML specifications and writing so many unit tests for this. I know not every project can go in this direction to this extent, but, I wanted to show where going in this path can take you.
So, even without service layer complications. You still have the model mapping tasks that (and this is what worries me) in many situations does not correspond to a “business” need. Note that I want to be doing Agile as well, and this makes the issue of delivering business value a true concern.
You can talk about automated generation for mapping. This may be something. We know it’ll not be this direct or one to one of course anyway, but it may help.
Would you do Domain Driven Design with “entity” models assuming the developers will stick to calling the repository’s “Persist” method instead of “entity.Save();”? You just can’t do that! How about new developers ? How about inconsistencies ?
Is mapping really that bad and much of an effort ? First look at it, I say it isn’t. But given complex scenarios I’ve been though I have to wonder about things like “complex object graph” and “caching” (in memory, on different levels, etc…).
It’s all about trying to calculate the costs indeed.


That’s what I’m trying to make out of this, the trick for the right cost.

Conclusion: How About YOU ??

Let me repeat the end of those messages:

Anyway, would love to hear your takes and what you have :) :) :).

If you have any thought on the topic, those will be most appreciated. You can comment here or in the topic messages page on ALT.NET Yahoo Group. This is an open discussion area, and I do not expect it to be closed soon.

Same, if you want to hear more ramblings on the topic, or just want me to shut it up all, send me a line.

Would love to see what others have to say about this….

dotNETwork 5th Gathering – Really enjoyed that Silverlight & SOA Anti Patterns Mix (Part II / II)

So, it has been exactly a week since I have been to dotNETwork 5th gathering. This is yet one of my too late events coverage (maybe I should write a long boring post about why that happens lately in as much annoying details as possible!). Let’s  hope we have something worth the wait this time …

Intro (No tech – you can skip)

This time I’m talking about the second session in the last gathering. The 1st session was already covered earlier. This session is special to me for two reasons: It was delivered by my of my dearest friends in the field, Mohamed Samy. I know Mohamed four years ago, since He was moving from VB 6 to C#, until he became one of the super guys in the field of enterprise computing and architecture in the .NET in Egypt, being a technical architect in ITWorx, one of the top posters in MSDN forums, and finally getting his Solution Architecture MVP lately (which he tells us a story about). The second reason is that I had the pleasure to see the latest part of his preparations for the session, and it was very interesting to see “the making” as well as “the show”.

Anyway, getting back to the session… The microphone stopped working at the very beginning. Mohamed moved to the middle of the rows and looked like a student leader talking to his fellows. this warmed things up a lot as well. He started warming them up by going really quick on his start as a developer, and choosing to continue in the technical career path (technical lead, architecture) while most prefer to take the manager path (project management, etc). He told us about his MVP how he was so happy to earn it in “Solution Architecture” then having the “Solution Architecture MVP” canceled, and having to choose a product specific MVP award instead. He went for “VSTS MVP” as relatively a bit close to his work, having “Solution Architecture” as a “competency” to the “VSTS MVP” award.

As we got lost in our way to the CIC (Canadian Collage, where the gathering took over), he mentioned that software is like finding the CIC, you ask people you find in your way about the road to go, each gives you a different answer. You need to get to that road and not ask again.

Going more into the session


Mohamed went through how “XML” suddenly became a buzzword. People tell you you’ll get rid of SQL and Oracle and replace them with XML files. It’ll solve all developer problems, and all this kind of talks. He bought a 1500+ pages book about being “proficient in XML” and he still didn’t understand what XML is really about. This is a buzz, just like the university sign, it tells you go certain way and everybody just follows. Later Mohamed recognized the simple fact that XML is just a text format based on tags that can be consumed within any platform. This is good because it solves communication problems between platforms (say COM from Microsoft and CORBA from Java) that were problematic because of using specific binary formats not text formats that before XML it was meaningful to prepare an entire PhD on communication between such platforms!

From this example, we see that every buzzword is said to solve all our problems. Few years later, the buzzword will just get deleted in favor of newer one. People need to understand the “concepts” behind the buzzwords not just how to use the tools and technologies related to them. He made fun of how people earlier earned so much money by writing about “Java & XML” when “Java” and “XML” were both buzzwords!

Patterns, Anti Patterns and Architecture

Getting more into the topic Mohamed asked the audience whether they know what patterns are. Well, few did! So, he explained “patterns” as solutions to common problems. He said that even architecture has much to do with this (more on that coming). Same as in building, there`re patterns in designing a living room or even a kitchen (like American furniture designs and such).

What happens is that someone faces a problem and solves it. Someone comes with better solution etc. and many people like it and repeat the same thing when solving the same problem. Someone draws UML diagrams and writes explanations for what the problem is and how the solution works, and this last work is what we call a pattern.

So, if patterns are the common practices we do to solve a repeated problem, then, following naming analogy, Anti Patterns will simply simply what what we should NOT do when soling our problems!

How about architecture? Lets use analogy with architecting buildings again. If a building buildings “designer” (similar to software designers) worries about the best use of spaces inside the buildings themselves, then the “architect” worries about the space “between” each building and the other, the green areas that should exist, where to have a garage, what ration should be between the building size and the width of the street it is build in, etc…An architect worries more about the interaction between systems and each other. Many applications have to talk to each other. Looking at a sample finance application, you may have an HR application that applies bonuses for example, for that, the HR application will have to talk to say a payroll financial application to apply the bonus payment.

But, not all applications run on the same platform, even more, each of them is likely designed in different way than the other. But we still need applications to talk to each others. That’s why we look at standard protocols, like HTTP, HTTPS and such. Those enable us to perform “integration” between those systems.

SOA, Who ??

SOA (Service Oriented Architecture) is an architectural style. What dos this mean? Well, back to buildings analogy. Mohamed showed pictures of example of Islam and Romanian architecture. All the audience could recognize each. The common parts in Islamic or Romanian architecture are what define an architecture style. The common parts between different architectures are what define the architecture style.

When you recall a 3-Tier architecture, you know what you are talking about, data access, business logic and UI. When talking about “Service” Oriented Architecture, you expect to see services.

What is the goal of SOA? Every architecture style has a goal. In buildings, why are the ceilings of the old houses very high? It was a pattern that solves a common problem. They no good fans or ACs back in that time, so, they made ceiling very high so that warm air goes up and less warm air remains in the normal height – to understand what the goal of SOA is, let’s get more on what SOA is.

SOA is an architectural style that emphasizes standards based integration between systems. This means enabling the components of different systems to talk to each other using standards. That’s one reason why WCF is good BTW, because it enables you to make components of the same system talk to each other in binary way, while still allowing components to talk to other components outside the same system using say XML. Clearly, this is not the easiest way to build applications nor one that guarantees success of the system. Not all applications should be built leveraging SOA, actually, trying to do SOA in all applications is a common mistake, Mohamed says. A Point of Sale (POS) application in a really small shop for example, has nothing t do with SOA.

Mohamed gave an example of Egypt back when there was no interaction between countries, all the goods are either made locally or very hard to get. Now, with all worldwide agreements, borders on getting and sending stuff are removed. SOA features standards: HTTP, SOAP, etc… It’s all about friction free interaction between different systems (again, standards based integration). It’s just a way of designing your application, a way of thinking.

Of course there’s lots of buzz/hype around SOA. You hear all that stuff about “Loose Coupling” and such. Some people might say applications should not not even know each other and have locators to tell them how to find each other. These are points of different opinions. Who said you need this overhead (or you don’t)? You still in all times have the overhead of translating from your internal system types and data to the standards format and the reverse overhead on the other system, so, if you are designing say a real time application with thousands of transactions in seconds, SOA will not work. If someone tells you 2e’ll go for SOA to improve performance, just tell him “you are so wrong”!

So, If I understood SOA is designing the system having services communicating with services of other systems using standard protocols like HTTP, and formats like XML, etc, etc… What is a “service” at all then? A service is an interface to your business process. When you are renewing your car driving license, you fill a form that is agreed upon between you and the responsible department, typically (does not quite happen in Egypt) you should be able to give it to only one terminal, without having to know say how many employees it goes to inside. This makes me personally think of a service as a method that will be called remotely with standards protocol and also parameters in standard format that a method caller should not worry about what the implementation of the method actually looks like.

The 4 tenets of SOA

By this we mean those tenets:

  • “Boundaries are explicit”
  • “Services are autonomous”
  • “Services share contract and policy not class”
  • “Service compatibility is about policy”
Boundaries are explicit

Mohamed showed a picture of a country border. There’s a fence, a STOP sign, a guy holding a microphone. If you are going full speed in the highway from Egypt to Libya, you have to stop at the border between the two countries (slows your total average speed). You also have to show say your passport and maybe visa (Authentication and Authorization). Services also have logical boundaries, could require authentication and authorization.

Also, when you re doing a money transfer from a country to another. you need to convert you local units in your country to the other country’s local units. For services, this is changing from the internal data types and schemas in your system to those of the system that has the service you want to connect to. Crossing the boundaries and doing the transfer takes time, that’s why we said that SOA is not the way to solve application slowness.

So, what are the boundaries of each service? We define that when we are architecting our services. We first agreed that those are logical boundaries. An example is, who should be able (and hence responsible) for changing a customer address? A sales application or a marketing application ? This is one kind of the questions we ask our selves when putting the boundaries.

Services are autonomous

If there’s a problem in having fish in Libya, should Egypt be affected by that? Of course no. Same with services. Each service should specialize in one operation. Services should be as least dependent on each other as possible.If service A depends on service B internally and for whatever reason service B is down, Service A should (ideally) still work with 100% its performance, or (more realistic) should provide downgraded performance. It should not be completely stopped.

Back to driving license renewal analogy. If the renewal requires getting your traffic offences, and those are got from say the ministry of justice that is down, it should tell you to come another day, or better off offers to give the renewed license to your house that other day. Note that “another day” is a degraded service.

The point is to make sure to not crash if the dependency is not found or down. Otherwise, a failure in one service, will fail all dependent services, that will cause failure to other services depending on them and so on, that you can easily find your entire company business down because of this.

Services share contract and policy not class && Service compatibility is about policy

The two are related. Back to countries analogy, to get the visa to travel from Egypt to Canada, you need to get police clearance(showing you are not a criminal). This is both a contract and policy. The contract is the police clearance certificate itself. The policy is that if the one applying is a criminal, s/he will not be allowed to get the visa.

For services, the contracts are the schema of data transferred between those services. The contract could be different from platform to another even when using standards. For example, if your service returns a customer record by sending a DataSet containing that record after applying XML serialization, the Java fellows trying to call your service will have hard time parsing the XML that gets generated from this serialization. Instead of that, you should send a typed Customer object XML document. A document that has the information needed clearly without any platform specific additional tags.

Policy is the protocol of the contract. For example, if the service requires authentication/authorization, works on HTTPS not HTTP or so, has certain timeout for results, etc… al this would be parts of the service policy. There’s an overlap between the policy and contract though (is the schema being XML or binary or what a policy or a contract?). In general, the policy is the definition of what’s allowed and required in the conversation between the service and its client (caller).

Thinking of contracts and policies, Mohamed showed that you should not require more data than you need. If your services just changes the address of the customer, it should require a “Customer Address” document not an entire “Customer” object document. This is called “Just Enough” Validation (MSDN). This is good also because the data is meant to come from a likely remote location, requiring less data will make things go faster.

One reminder on polices as well. This is like whether to use SSL or not, what protocol to go to, what to enforce, etc.. Mohamed mentioned the WS-* specifications that can give you in-the-box encryption, trust, transaction and other services, but there was no room to talk about WS-* here as we needed to move to the title of the session, SOA Anti Patterns ….

The Anti-Patterns

The session was originally called “Patterns and Anti Patterns of SOA”, due to time limitation, and prior permission from the dotNETwork guys, the session was split to two parts. One for the patterns, and one the anti patterns, which Mohamed has chosen to start with Anti Patterns as to clear up the thinking before telling us what we should be doing. He’s more interested in what SOA is NOT than what it IS. Let’s see what he talked us about…

Remember, this is what you should NOT do.

Anti Pattern: “CRUDy Interface”

OK, so we want to start SOA, and want to expose our system components as services. Let’s start by the easiest parts. Our system will always have to deal with Create (Insert), Read (Select), Update, and Delete operations (CRUD). Lets create services that encapsulate those – WRONG.

Changing a record can have so many side effects, let’s take an example of changing a customer address. This sounds very direct (update customer set address = …), and that’s it. Not really! If you change a customer address, many things could change as well. Tax rate for example. In Nasr City district in Cairo there’s some area called “Free Zone” or “El mantea’a El Horra”. If your business is in it, you’re exempted from taxes for certain years. If your business is anywhere else in Nasr City or Egypt in general you do not get that. So, changing an address from or to this area even still within Nasr city can have a big effect. Also, you may want to send an email to the branch that the customer will be transferred to when changing address, so, this is taking an action not just changing the address.

It happens in reality. If you change your address in the ID card, it does not affect your driving license, passport info, or bank account. Some guys came with an argument that it should, as al the systems should have the same database. Mohamed said that in reality we could have very good system for banking running ith IBM stuff, a good system for car licenses running on SQL server, while the ID system might be Oracle based. Because the systems are already packaged into different databases and database schemas, they just cannot share the same DB.

Anti Pattern: “Enumeration”

This means something like CustomerService.MoveNext();. A virtual curser  (meaning a pointer, not SQL curser). This allows the client to treat the data and iterate (loop) on them as if they were already loaded to the client, while they’re truly on the server. For the server to be able to enable this. It’ll have to hold the entire list for each client, and that would be a huge performance headache on the server, and the service should not have to worry about caching this and storing the last position and such. Remember (from the tenets) that services are autonomous. A service should care about one operation.

To explain this, Mohamed mentioned a system he joined in the past after it was created. There was too much work done on the DB server for updating recording dependant on each other and/or updating some complex calculations fields, etc.. This was done via SQL dynamic cursors. The cursors have been running all day locking the data in the DB from being accessed by any application.

The point is, the consumer (AKA client) of your service should not be the one who controls your server resources. You have no guarantee who’ll call the services. Even more, you have no guarantee who wrote the code that will call your service (even if you know which system it is via authentication), and you cannot guarantee whether they’re good developers or not.

Anti Pattern: “Chatty Interface”

This is when you require say 5 different service calls to do the same thing. Something like Customer.MarkForDelete(); Customer.Delete();. Two calls to perform deletion. This way you required the consumer to go all the way long from the client to your server and backwards two times instead of one. Well, not just that, how about if “MarkForDelete();” was called first and “Delete();” was never called??

This is actually something you may want to do in some certain cases, but most of the time you don’t. The problems with this are the additional time things will take to perform just one operation, and that it can easily get your data into an inconsistent state. If some of the steps were called and the next steps were for whatever reason not called, your system now has a weird state!

Anti Pattern: “Loosy Goosy”

Why don’t you just make all your services a single services that looks like XmlDocument PerformOperation(XmlDocument input) {…} ? BAD BAD BAD.

The point here is the difference between implicit and explicit behavior. If you do the example above, how would the clients know the way to call a certain operation than another? How will they know what data you need to be filled in the input XML or what to expect in the returned XML? An explicit behavior DOES matter. When creating your services, give them good names that shows what operation each service does perform. When defining your inputs, remember the “Just Enough” Validation rule. Make XML schema for the fields you need only better than using  a bigger XML schema that already exists. A services that updates a customer address only required a CustomerAddress document (With address and ID inside) not an entire Customer object document. You should also be explicit about what the service returns, whether nothing, a document with certain info, etc..

Why is implicit behavior bad anyway? Mohamed gave a very funny example.He went to work on an old COBOL based government system for salaries (salary laws were defined in 1936 and had endless changes afterwards all handled by this system),. The system was a single long routine with no modularity at all, and when trying to make it more modular, Mohamed got stopped at an entry point to the application that takes 3 flags.ZEFT (Asphalt), MIDO (fun name), SOSO (fun name). He couldn’t know what those 3 flags refer to until he asked the people using the system. They told him the woman who created this system has chosen MIDO as per the name of her son, SOSO as per the name of her daughter, and ZEFT (meaning asphalt) as per the name of  ….. whatever :D.

People kept  a notebook including what exactly the operations that are performed when you set ZEFT, MIDO and SOSO to certain different numbers. You can imagine what maintenance nightmare Mohamed found himself in, and this is exactly the nightmare you give your clients when you go for an implicit behavior. Mohamed says it’s like a house of dominos. It doesn’t survive long.

Last thing Mohamed mentioned was about the “Just Enough” Validation. What would you if your system earlier required a customer document with single field for address and now happened to have different fields (Line1, Line2, City,…). You then need to version your services. He showed how this can be done with XML serialization of objects. The main idea is you use your platform native types as long as you are inside the same system’s boundaries, and serialize/de-serialize that to/from different XML documents when returning/accepting XML data in your service. You can apply “version” and “optional” flags to allow versioning of the documents.

Just after the session, I asked Mohamed to show his Links slid, and guess what? He had my blog (with the old GeeksWithBlogs URL he likes more than this one) in his SOA recommended readings!!! I can’t pretend like I didn’t know it, having asked him for the references myself made it very embarrassing to me. But anyway, thanks a lot, Mohamed for this invaluable trust.


As I mentioned before, these are only the Anti-Patterns. The patterns are to come in the next gathering in July (God Willing).

Now to my comment: Mohamed did well for a guy explaining this to people who did not know what design patterns are. I’ve seen few advanced developers sitting in between and they were looking satisfied too. The microphone problem was a good thing for him. Everybody was happy, but for me, I was still missing some. Maybe that’s why he kept kidding with me about along the session “you feeling OK now, Meligy? :D :D” :D :D :D.

I didn’t like that he assumed SOA is all about SOAP and WS-* while other paradigms exist like REST and such, but I cannot blame him at all, as mentioning such would probably cause a huge disturbance to people and could simply get them completely lost. I also was sometimes losing the software example that maps to the building/countries/real-life examples he gave. That was in few cases though. Maybe I just wanted to hear so much technical stuff though! One more thing is that he had a very interesting flow of the talk that he could highlight and clarify a point either before or after its original place in the presentation. This didn’t cause people confusion, but it was really tiring when  came to transfer my session notes into this blog post, that I feel it does not tell the content of the session in a proper way.

Generally it was a very good session. If you could please people with different knowledge levels to good percentages in such a complex topic, then you have done something. Good job, Mohamed. You DID meet my expectations. I’ll be there for the Patterns session (God Willing).

BTW, Mohamed is now working on getting his VSTS related portal, theVSTSguy. I’ll update this blog as soon as he gets it up and running.

dotNETwork 5th Gathering – Silverlight and what ? SOA Patterns, Yay!!

n587461065_1343848_971The 5th dotNETwork gathering will be: Saturday, June 28, 2008.

The agenda is as follows:

12:00 AM – 01:30: Delivering Rich User Experience Applications using Silverlight 2 by Yasser Makram

01:30 PM – 2:00 PM: Coffee Break

02:00 PM – 3:30 PM: Patterns and antipatterns of SOA by Mohamed Samy

03:30 PM – 4:00 PM: Lunch


It’ll be in: Canadian International College Busses will be available at: Nady El-Sekka (11:00 AM – 11:30 AM).

The gathering being on Sunday not Saturday as usual makes it harder to attend it The gathering facebook event said by mistake it’ll be on Sunday, but it’ll be on Saturday normally like all other dotNETwork events.

Regarding the sessions

I do not know about Yasser, but Silverlight 2.0 is a fairly new topic and it’ll sure be interesting to come and see it. I think Yasser will bring us a lot of amazement!

For the SOA topic, I want you all to set high expectations starting now. Mohamed Samy is a Solution Architecture (VSTS) MVP who has worked in and talked about SOA patterns more than most people I have met in person as both a personal passion and a job responsibility as a Technical Architect in ITWorx. I know Mohamed in person and believe he’ll be delivering a rocking session. Do not miss that.


Related Resources



I’ve already started finished my writings. Here are the published blog posts:

Enterprise Service Bus Messaging Using nServiceBus

I have been working lately with a big group of fellow developers here in SilverKey on the architecture and design of a relatively big project that required much services and messaging work. We thought that we should implement our public services the REST way using WCF for .NET 3.5, with so many customizations, and that we’ll use a library called nServiceBus for internal messaging. Mohammed Nour wrote a little about thinking in REST.

nServiceBus is a framework for handling publisher/subscriber (pub/sub) model of messaging. It provides reliable messaging via the Enterprise Service Bus (ESB) pattern, and uses MSMQ as the physical bus.

It’s an interesting piece of work to look at actually; of course free, open source. I have been involved in evaluating it for our project, and wrote a document about it as part of my work, so that it’s easier for the rest of the team to use it later. As the documentation for nServiceBus is very limited at this stage of the project, I and my boss Dody decided to share the document with the community.

Another very important reason for this is enabling the nServiceBus group to correct and enhance the document as much as possible. That’s why the document is published under the Creative Commons Attribution-Share Alike 3.0 Unported License.

Download the document

WARNING: This IS going to change, see the nServiceBus Yahoo group for updates to this document.

If you are lazy to download check this out:

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.

Revision History

Author: Mohammad Meligy

Revision Number: 1.1


Status: Public Draft

Last Updated:

Feature ID:

Related Document(s):



Revision History    2

Overview    4

Context    4

Glossary    4

Requirements    5

Goals    5

Non Goals    5

Major Features    5

Dependencies    5

Usage    6

How it works    6

Defining the message contracts    6

Writing the code to handle the messages    6

Setting up messaging communication    7

Logging (Optional)    12

Security Consideration    12

Security Constraints    12

FAQ    13




This document shows the use of nServiceBus library (www.nservicebus.com) for managing enterprise messaging using the service bus pattern. The model explained is an advancement of a publisher / subscriber model.


The document is written to be guidance for developers involved in intercommunication between components in enterprise project, however, it is written with no specific relevance to the project components, and can be used for any project that implements this kind of messaging.


There’re some common terms used in this document:

  • Message

    A message is the object that groups the data you want to pass from a module to another module or system for processing outside your module.

  • Publisher

    This is the code that creates the message and puts it publicly to be available for later processing.

    Note: It’s very common when dealing with nServiceBus to call the publisher as a "Client"

  • Subscriber

    This is the code that checks for published messages and passes is responsible for performing any desired operations on them.

    Note that the subscriber that subscribes to a certain request message for example may want to send a response message in return, hence, it then acts as a publisher, and so. It’s normal that the module that acts as a publisher acts also as a subscriber and vice-versa.

    Note: It’s very common when dealing with nServiceBus to call the subscriber as a "Server"

  • Service Bus

    This is the shared message store where all the messages are be written to by the publishers requesting processing, and then later read by the subscribers for processing. Once the messages are delivered to subscribers, they’re typically removed from the message store.




  1. Enable asynchronous messaging across multiple servers.
  2. Ensure reliability for the asynchronous messaging.
  3. Enable a publisher / subscriber model for the messaging.
  4. Enable multiple subscribers to each published message.
  5. Enable a publisher to receive response messages from subscribers.

Non Goals

  1. Enable canceling of already published messages.
  2. Specify the sequence of message subscribers handling via configuration (still available from inside the subscriber code).

Major Features

  1. Setting a server to act as service bus for multiple publishers/subscribers.
  2. Setting the publishers to send messaging to a service bus asynchronously.
  3. Setting multiple subscribers inside a service bus.
  4. Limiting the handling of messages based on their type.


  1. MSMQ – Acts as store for published messages
  2. Spring.NET Library (On all the publisher and subscriber application – included with nServiceBus assemblies) – For initializing the messaging infrastructure
  3. Log4net Library (http://logging.apache.org/log4net) – For logging purposes
  4. Serialization (On all the code classes that are included in published / returned messages)




How it works

You create the message type, create a type that holds the processing of the message (called message handler), configure the publisher and create the message instance itself that it publishes to the bus, and, configure the subscriber to subscribe to the bus and map the message instance to new message handler instance.

You’ll notice that the difference between the client and the server is really small. A client publishes a message to one or more primary buses. The server subscribes to the messages it has handlers for that come on the primary bus. But, for the server to be able to send back "response" messages to the client, the client also has its own bus (queue) that it subscribes to for handling response messages.


Defining the message contracts

You define the message type (class) normally in any VS project with certain considerations:

  1. It should implements an interface "NServiceBus.IMessage".

    This interface does not require you to implement any methods / properties.

  2. It should be attributed as "Serializable".
  3. It’s highly recommended that your message have an identity field of type GUID.


This message acts as data contract between the publisher and subscriber, and it should be available to both. This is the actual data that’s being passed between them.



Writing the code to handle the messages

A handler is the business logic that does the actual processing of a message. When the subscriber receives a message, it checks which handler(s) it should call to process this message. A handler is independent from the subscriber and can be used with multiple subscribers though.

When creating the handler type (class), you should either

  • implement the interface "NServiceBus.IMessageHandler<MESSAGE_TYPE>"
  • Inherit from class "NServiceBus.BaseMessageHandler<MESSAGE_TYPE>"

MESSAGE_TYPE is the type of the message to handle.

The two options are equal in effect. You write a method "public void Handle(MESSAGE_TYPE)" where you write the code that actually processes the message.

Note: You can implement the interface multiple times for MESSAGE_TYPE_1, MESSAGE_TYPE_2, etc, and then you have to implement the methods "public void Handle(MESSAGE_TYPE_1)" and "public void Handle(MESSAGE_TYPE_2)", etc.


In this example, the handler just creates a message of a different type (which it does not have to do or have to define) and sends it to the service buss.

The last line has the method "Reply" which accepts "paramas" of message(s) that act as response to the original message and sends the response message(s) back to the queue of the client (who sent the original request message).

Error Codes

To indicate that there was an error processing the message. NServiceBus promotes error codes and creating custom messages that represent the error against throwing an exception.

Here’s a sample code or creating "enum" for wrapping error codes and returning it:


Setting up messaging communication

Now, you have a message type, and a message handler. What’s remaining is writing the publisher that sends this message to the service bus, and the subscriber that asks the service bus to subscribe to any message of the type(s) you want, and before all that, creating the service bus itself.


Preparing the service bus

The first thing you need to do is to create the MSMQ queue that acts as a service bus. The name of the queue will later be available to publishers and subscribers to write messages to / read messages from.


Creating the publisher

The publisher is the code that sends the messages to the service bus through configurations. Before writing anything, you need to add references to the following assemblies:

  1. NServiceBus
  2. NServiceBus.UniCast
  3. NServiceBus.UniCast.Subscriptions
  4. NServiceBus.UniCast.Subscriptions.Msmq
  5. NServiceBus.UniCast.Transport
  6. NServiceBus.UniCast.Transport.Msmq
  7. utils

The way nServiceBus highly promotes is setting the publisher configuration in the app.config/web.config of the Visual Studio project that contains publishing code using Spring.Net configuration.

A typical configuration looks like this:

  1. A configuration section that registers the Spring.Net configurations

    The "Common" and "log4net" parts are optional and are only used in case you want to use logging.

  2. Create the standard sections for Spring.NET

  3. Replace the part "<!– All the required configuration for nServiceBus comes here –>" with the actual configuration to use. A typical configuration looks like:

    The properties that matter in this context are:

  • "Transport"
    • "InputQueue"

      Sets the path to the queue where the messages will be read from. This is essential as the publisher might also subscribe to messages (typically responses to published requests).

      Note: For MSMQ v3 (Windows XP, 2003), this must be a local queue.

  • "Message Owners"

    This connects the message – based on the message type (class, the one that implements "IMessage" interface) – to the MSMQ address where it will be published.

    As shown above, this is written as a dictionary, where:

    • "key": is either the name of the message type (class) – or – the name of an assembly, so that nServiceBus looks inside this assembly and locate all the classes that implement the "IMessage" interface.
    • "value": is name of the MSMQ queue to publish the "key" messages to
  1. Write the actual code that sends the message to the service bus

    In this sample, "RequestDataMessage" is just the message type (class).

    The code is pretty simple, you:

  • Use Spring.NET to create the service buss
  • Create the message itself normally and fill its members
  • Send the message to be published to the bus (This has some alternatives discussed later)
  1. As the message is published asynchronously, you can optionally create a callback method that handles the message. A code for something like that would look like:

    You send the message and sending returns an "ICallback" object. This object has single method "Register" which you use to register "AsyncCallback" delegate to a method that will be called asynchronously when the sever returns a reply, which is "RequestDataComplete" in our example. A sample implementation of this method would look like:

    Clearly, you can see that result returned is a "NServiceBus.CompletionResult" which has both "state" which has the original sent message, and "messages" which has the response messages.


Creating the subscriber

The subscriber is the code that reads the messages published to the service bus, and pass the messages to the messages handler(s) set for it.

The configuration for the subscriber is very similar to the publisher:

  1. Steps 1 to 3 in the publisher are the same for the subscriber
  2. The final nServiceBus specific configurations would look like:

    Note the following sections as well:

  • "Transport"
    • "InputQueue"

      This is the MSMQ queue that the subscriber will listen to.

  • "SubscriptionStorage"
    • "Queue"

      This is the MSMQ queue where the subscription messages will be stored (The mapping between the subscriber and publishers)

      Note: For MSMQ v3 (Windows XP, 2003), this must be a local queue.

  • "MessageHandlerAssemblies"

    This is a list of assemblies to look in for message handler types (classes, ones that implement "NServiceBus.IMessageHandler<MESSAGE_TYPE>"), so that it maps the handlers to the messages it receives

  1. Writing the actual code that subscribes to the bus. This is very simple piece of code

    You can see it’s very simple. You create the "Bus" object from the information in the config file using the "Spring" library, and just start the bus. It loads all the necessary information like which messages to subscribe to and the mapping between message types and message handlers, etc, from the config.

  2. Now you need to deploy the code that runs the server. Note that the bus should be living forever! You’ll want to treat it as you treat a Windows Workflow Foundation Workflow Runtime for example. Either make it an independent Windows Service, or write it in some Application even of the global.asax of a web application.


Logging (Optional)

For the error logging and such, nServiceBus library has dependency on another library called Log4net. You can use that for any kind of logging. Sample logging code looks like:

For Log4net library specific documentation check


Security Consideration

Seeing how nServiceBus works, you notice you have typically two queues, one for the server and another for the client. You also notice that you have two operations for each, read and write.

Security Constraints

To setup MSMQ, you can use public queues, but those are hard to create and are very insecure. Typically you use the default private queues. This causes few constraints on the queue operations.

  • For reading from the queue (AKA subscribing to the bus), the queue has to be on the same machine as the subscriber. You cannot subscribe to a queue that is on a different machine if you are using MSMQ version 3 (like using Windows 2003).
  • To write to the queue (AKA, publish to the bus), the OS process running client/publisher has to be running with a use account that has sufficient privileges on the machine that has the queue you want to write to. This means you’ll typically be running the client and server on two machines in the same LAN with Active directory and sufficient user access, which is a common scenario anyway.


  1. Where to find a copy of the examples in this document or get a working example for nServiceBus in general?

    The code snippets in this document are mostly coming from the "FullDuplex" example that comes with the library source code.

    The source code can be found at: http://sourceforge.net/projects/nservicebus

    For more examples, check the library Yahoo group at: http://tech.groups.yahoo.com/group/nservicebus

  2. When I downloaded the nServiceBus source from the library SVN repository I found the configuration much different than described in this document. Any Idea?

    The next version of nServiceBus will have different configuration. It’s not documented here because it’s NOT a complete release yet so is still subject to change before the next release.

    For differences between the configuration of the current release and the upcoming release, check nServiceBus wiki page at: http://nservicebus.wiki.sourceforge.net/Configuration

    There’s also incomplete documentation of the examples on nServiceBus wiki at http://nservicebus.wiki.sourceforge.net/Samples

  3. Is there any documentation for nServiceBus?

    There are few resources:

However, most of those are either very limited or incomplete.

  1. How do I write the name of a MSMQ queue that exists on a different computer?

    You write the name of the queue in a format like "QUEUE_NAME @MACHINE_NAME"

    MACHINE_NAME is the computer name of the machine that has the queue.
    QUEUE_NAME is the name of the queue itself