wiki:WikiStart

CorePoint.DomainObjects for Sitecore 5.3 and 6.0

Welcome to CorePoint.DomainObjects

Copyright 2008, CorePoint IT Limited
E-mail: domainobjects [at] corepoint-it.com
Web:  http://www.corepoint-it.com

CorePoint.DomainObjects is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

CorePoint.DomainObjects is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with CorePoint.DomainObjects. If not, see < http://www.gnu.org/licenses/>.

Links to get you started

 Getting started

 Sitecore 5.3 Package

 Sitecore 6.0 Package

 API Documentation

 C# Source/Project Files (VS 2008)

 SVN Repository Link


 Update 1 for CorePoint.DomainObjects - Sitecore 5

 Update 1 for CorePoint.DomainObjects - Sitecore 6

Update 1 fixes a bug that would cause exceptions when attempting to map !Sitecore.!Data.!Fields.ImageField to DomainObject properties. Further; the StandardTemplate object learned a few new tricks ;-)


 Update 2 for CorePoint.DomainObjects - Sitecore 6

  • Unless somebody requests them, Sitecore 5 release packages will no longer be released. The source can still be built against Sitecore 5 however, and will be unittested against 071114.
  • Update 2 includes minor updates and support for .GetReferrers. .GetReferrers will (via the LinkDatabase) get all relations to the selected DomainObject (via MultiList, TreeList and so on)

 Update 3 for Sitecore 6

  • Fixes an issue where multiple language versions of the same DomainObject would not get added correctly to Sitecore
  • Now includes support for Versioned and Unversioned Media DomainObjects. You should hopefully find the implementation and use to be very straightforward.
  • By request, now includes support for Sitecore Query. Look for .QuerySingleObject and .QueryMultipleObjects

Unlike prior update releases, I've not had a whole lot of time to work with this update myself yet. Any feedback on the use of the new media items would be particularly appreciated, but any and all feedback is of course welcomed.

Am hoping to get updated sources and updated documentation released later this week.


What is CorePoint.DomainObjects?

Essentially, it's a tool for Sitecore developers and integrators designed to make tasks relating to Sitecore data and Sitecore data storage easier. By easier, it is implied that working facilitating means to allow for a "cleaner" interface between the business domain and the Sitecore domain, maintenance will be easier, implementation time will be shorter, transition between Sitecore versions will be easier, life will be better ;-)

As the name would imply, CorePoint.DomainObjects aims to allow developers to implement something resembling (but won't truly be, however it comes close) Martin Fowler's  Domain Model. Well technically speaking, the model isn't "his" as such, but he is probably directly responsible for making it so well known.

The Domain Model differs quite a lot from the approach you generally see in MSDN or SDN or in code snippets in general. There is a reason for that. First of all, a Domain Model follows OO design methodologies and in its nature it is therefore not easy in the space of an example code snippet to implement something from start to finish. For instance, was I to demonstrate how to pull out all orderlines on an order, I might write up an example such as this:

(pseudo code - sort of)

DataRow o = ordersTable.Rows[10];
orderLines.Filter = "OrderID = " + o["OrderID"];
foreach (DataRow orderLine in orderLines)
    Console.WriteLine( orderLine["Price"].ToString() );

The example essentially explains the points I needed to make. There is an "ordersTable". The key connecting "order" to "orderLine" is "OrderID".

Writing the same code in a Domain Model might look something like this:

Order order = OrderBook.GetOrder( 10 );
foreach ( OrderLine orderLine in order.OrderLines )
    Console.WriteLine( orderLine.Price.ToString() );

But then I would also have to document additional things:

The structure of the Order class.

The structure of the OrderLine class.

The structure of the OrderBook class.

Each of these could easily be 20-30 lines of code, just for enough to cover the example. And it's just not practical.

But that does mean you shouldn't be coding it in this way? Well opinions differ of course, but I would say absolutely not. Try escalating the type of code in the first example into a massive big solution. There will quickly be 100s of points in your code, where assumptions are made on exactly how an OrderLine relates to an Order. Now imagine you were tasked with changing something critical, in the way this worked... Now you're in trouble.

The Domain Object model aims to help you in exactly this situation (and quite many more). It certainly to me, has proven time and time again, to be an absolute lifesaver. Better (and very testable) code, quicker implementation, easier maintenance and so on.

Sitecore developers themselves have been around this subject matter in the past as well.  Custom Item Sitecore API Pattern Explained touches base, but uses a slightly different approach than seen in CorePoint.DomainObjects. Essentially, the method he describes here, resembles the  Decorator Pattern. And while this is certainly a valid approach, it has it's uses and limitations (as the author rightfully states himself). Personally, I would prefer to fully be able to benefit from OO design and the seamless ease that the Domain Object model offers. Further, using Object Composition like Alexey demonstrates in his article, will still leave your objects closely knitted to the specific Sitecore version and it's API - which from a long term code maintenance perspective is probably not ideal.

Enough rambling for now. Take a look around, and enjoy CorePoint.DomainObjects.

Attachments