S#arp Architecture

Let's start by summarizing all the approaches to transactions we have so far:

  • we have the #arch Transaction attribute
  • we have the contrib Transaction attribute
  • we have the control UnitOfWork attribute

What are they for? What do they do? How to choose?

Some info which should be put together in a nice wiki page is in the following threads:


Here is the contents of the post which triggered the creation of this page, with several questions to be answered:

1) How does the SA Contrib Transaction Attribute relate to the regular SA Transaction Attribute?

Can you use them together? For example, decorate the Controller action method with an SA Transaction Attribute, and then decorate the Domain Services (or Application Services) that the controller invokes with the SA Contrib Transaction Attribute?

2) How does the SA Contrib Transaction Attribute relate to the SA Contrib UnitOfWork Attribute?

The documentation seems to be conflicting here:

"Transaction PostSharp Attribute (Supports NHibernate or System.Transaction. Works With ASP.NET, WCF, Windows GUI and Windows Service Applications)" http://wiki.sharparchitecture.net/SharpArchContrib.ashx

"You should use UnitOfWork in all Windows applications." http://wiki.sharparchitecture.net/ContribUnitOfWork.ashx

Can the SA Contrib Transaction Attribute be used in a non-web application?

3) Where should transaction management be placed? What layer is it a concern of?

I've seen two general camps:

3a - Handle transactions in the Web.Controllers level with the SA Transaction Attribute

3b - Handle transactions in the DomainServices or ApplicationServices layers (presumably with the SA Contrib Transaction Attribute)

Is SA able to work with both types of setup?

4) How should exceptions be handled, in the context of transactions?

5) There are two types of transactions: NHibernate transactions, and standard .NET transactions (Transaction.TransactionScope).

They are sometimes confused. Can the two be mixed? In what circumstances should they be used together, if at all?

6) How can we utilize SA in a multi-client paradigm, in relation to transactions?

This is the biggie for me, and likely crosses over all of the above questions. Say I want my "core" app to be based of SA (Domain, DomainServices, Infrastructure, etc), and then say I want to use this "core" in both an SA-enabled website and another type of client (non- SA enabled), like a Windows App or Service.

How can this be achieved? How can the "core" be implemented, so that it can function in both "contexts"?

Since we are in DDD-land, a bit of terminology disclaiming is in order:

Domain - POCO models DomainServices - Domain level services/tasks that cross/mix (involve more than one) entities (aggregate roots) AppServices - Infrastructure level services. Services/processes like "SendEmail" or "WriteFile" that involve interaction with external resources

ScrewTurn Wiki version 2.0.36. Some of the icons created by FamFamFam.