Update to DomainTypes library

February 20th, 2010

The initial release of DomainTypes was heavily influenced by the existing TrueView framework.  After spending much time working with a current client, it’s clear that a more ‘POCO’ approach has significantly more benefits.

Based on my findings (and questions over at StackOverflow), here are the major changes:

  • Refined and enhanced most of the interfaces
  • Removed the concept of persistent and transient classes
  • Domain Services and Application Services have explicit interfaces
  • Domain Objects no longer implement IDependencyAware
  • Removed the ITrackable interface

I’ve also added more examples to clarify how you might use the interfaces.

You can download the code here.  All comments are welcome.

P.S. Note that this library is NOT compatible with the current TrueView framework.  Watch this space for the new version!

http://evolving-software.co.uk/blog/wp-admin/post-new.php

Merry Christmas and a Happy New Year!

December 24th, 2009

A new version of TrueView is in the pipeline for next year.  The features on the whiteboard are:

  • Better support for true DDD concepts
  • Allow code models to be reused without TrueView
  • Configuration without using .NET attributes
  • Open architecture, to let consumers develop custom ‘persistence providers’
  • More UI interception points, to allow greater customisation
  • Auto-databinding features, for WPF and possibly Silverlight
  • N-Tier support (finally)

And we’re considering making TrueView FREE for non-commercial use.

We’re going to need beta-testers for the new version, so if you’re interested please email us.

In the meantime, have a very Happy Christmas!

Domain Types – Interfaces

November 24th, 2009

In the last post, I published the DomainTypes library: a set of .NET interfaces & base classes to provide the building blocks for DDD (source code included).

In this post I’ll describe the interfaces and supporting design decisions.

IDomainObject

Represents any type of object within the Domain model. Currently this is simply used as a marker, signalling to developers that the implementation has DDD semantics.

IEntity

Represents a unique Entity within the system.  The ID property is used to identify the instance during it’s lifetime.  Using a GUID allows identity to be established without having to talk to a persistence store (i.e. database).

IValueObject

Represents a non-unique object within the system.  Note that it’s an object, and not a struct.  Structs may seem like a better semantic fit with DDD, but too many instances can cause memory problems (structs – like value types – are created on the stack).

The Clone() method is used to create copies.  The implementing class can decide whether to create new instances, or use the FlyWeight pattern.

IList<T>

Represents a list of Domain Objects.  It’s crucial that the implementing class raises events before items are added or removed from the list.  This allows consumer code to execute any domain rules, and cancel the action if necessary.

IEvent

This is one that Eric Evans mentioned earlier this year.  It is used to record & identify domain events, and must be immutable. For example, a child’s birth should be captured, be identifiable, but never modified.

IAggregateRoot

Most people understand Aggregate Roots as a cluster of closely associated entities.  However, there are 2 additional concerns that an Aggregate Root has:

  1. It knows how to validate the entire aggregate
  2. It is used to lock it’s contents in a multi-user environment

The IsConsistent() method is a placeholder for all rules/invariants that apply to the aggregate.  The locking concerns are handled by IRepository<T> (see below).

IFactory<T>

Used to create Domain Objects/Entities/Aggregate Roots that are complex to build.  Only use factories when the code within your constructors becomes unweildy.

IRepository<T>

Used as a facade to a persistence store.  Strictly speaking, repositories should only deal with Aggregate Roots – to access other entities you would navigate through the Aggregate.

In addition to the typical Load()/Save()/Delete() methods, I’ve also included Lock() and Unlock() methods.  This is a crucial function in a multi-user system, and should be considered when designing your Aggregates.

IService

Currently this is simply used as a marker.  Only consider using Services if :

  1. Try as you might, you can’t decide on which Domain Object to place your logic
  2. The logic requires the use of several unassociated Domain Objects
  3. You’re communicating with another module/tier/component

The remaining interfaces aren’t DDD specific, but are to aid real-world implementations.  I’ll discuss those in the near future.

Download the source code

Free .NET type library for Domain Driven Design + source code

November 19th, 2009

I’ve observed a lot of newcomers to the DDD scene, and typically there’s lots of talk about Entities, Value Objects, Aggregate Roots, Repositories, Factories, IoC, and various technical concerns.

But I’m seeing a lot missing from the discussions.  Like “What about the locking implications around an Aggregate?” or “Must Value Objects be immutable“, or even “How do entities retrieve data if they can’t access a repository?“.

To that end, I’ve created a set of interfaces and base classes that represent the building blocks of DDD.  The idea is to get developers thinking about key concepts early in the design process, and let Intellisense provide some guidance.

You can download the source code here.  It has a Ms-Pl licence, so you can modify and use the code as you wish.

The DDD related interfaces are:

  • IDomainObject
  • IEntity
  • IAggregateRoot
  • IValueObject
  • IList<T>
  • IFactory<T>
  • IRepository<T>
  • IService<T>
  • ISpecification<T>
  • IQuerySpecification<TRequestor, TResult>

Additional interfaces for orthogonal concerns are:

  • IPersistable
  • IPersistableList<T>
  • IAudit
  • IAggregateLock
  • IAssertion
  • IDependencyAware
  • IDependencyLocator
  • ITrackable

Interfaces

This is still a work-in-progress, so feedback would be greatly appreciated.  In the next couple of posts, I’ll describe the interfaces and classes.

Download the C# project

P.S. The next version of TrueView will be based on these interfaces.  So if you code a domain model using the compiled library, TrueView will auto-generate a completely interactive UI (with the appropriate semantics) directly from your model.

Domain Driven Design reference card

November 17th, 2009

Spotted this handy online reference for Domain Driven Design:

http://www.scribd.com/doc/21997741/DZone-Refcard-76-Domain-Driven-Design

Upgrade from Windows 7 beta/RC to Windows 7 RTM

October 5th, 2009

Finally got around to upgrading to Windows 7 RTM, only to be greeted with the following:

You cannot upgrade this prerelease version of Windows 7. Go online to see how to install Windows 7 and keep your files and settings

A quick Google found these instructions.   Should save you the hassle of rebuilding your PC :)

TrueView Maintenance Release 1.3.0908.21

August 21st, 2009

The latest release has some UI fixes for TrueView, and mapping fixes for DataBridge.  Download it here.

TrueView Fixes

  • UI now shows changes if entities are modified inside constructors
  • Corrected treenode selection when removing a previously selected node
  • Fixed race condition when opening Entity property nodes
  • Entity Property treenode no longer renders with the Entity’s style
  • Fixed window layout for magnetic windows
  • Fixed window positioning when overlaying windows
  • Correctly identifies the top-most window in multi-monitor mode
  • Exceptions when retrieving Summary value are no longer fatal
  • Fixed Search Results window ownership in MyApplication.Load<T>(query, parameters)
  • Shortcut key presses are now handled for multi-monitor mode

Enhancements

  • ‘Short’ values now have smaller widgets (Strings)
  • Improved ‘Version Check’ dialog messages

DataBridge Fixes

  • Corrected writing of Component properties
  • Fixed Foreign Key names for Entity properties of the same type

Multi-monitor support and popup Search Queries

August 10th, 2009

The latest release includes 2 very useful UI features:

Multi-monitor support

This option is specially useful when you’re demoing to others, and can be enabled from Tools->Options->UI Settings->Allow MultiMonitor Use. All subsequent windows will open outside of the Workbench, allowing them to be dragged to other monitors.

Popup Search Dialogs

Although drag & drop is very powerful, not all users are comfortable with it, instead preferring to select items from a list.  With this is mind, a new context menu item was added:

popup-search-dialog-for-entity-property

Selecting this will open a Search Dialog, where the user can query and select an Entity.  It also works for EntityList properties (multiple Entities can be selected in this case):

popup-search-dialog-for-entitylist-property

It’s also possible to pre-load the popup search dialog using Query Specifications.  See the section “Pre-filtered Search Query Dialogs” in the user guide to learn more.

TrueView Release 1.3.0908.09 – ServiceLocator and Dependency Injection

August 9th, 2009

The latest release adds Dependency Injection to the mix.  The default behaviour uses a simple Service Locator, but you can inject your own dependencies as you wish.  See the user guide for more info.

BREAKING CHANGES:

The following interfaces now implement IServiceDependent:

  • IEntity
  • IFactory
  • IRepository
  • IService

Enhancements

  • Added MyApplication.ServiceLocator (for locating Factory/Repository/Service classes)
  • Added IServiceDependent for DependencyInjection services
  • Added IService interface (similar to IFactory and IRepository)
  • Services are now shown in the Class Library treeview
  • MyApplication now raises EntityCreated event when entities come into scope
  • MyApplication now raises EntityDisposed event when entities are no longer required
  • MyApplication now raises ApplicationInitialised event at startup
  • Many delegates moved out of classes (reduce API clutter)
  • Added EntityListAttribute.HasUniqueItems, to determine if duplicate items are allowed
  • Drag/Drop tip now detects duplicate items
  • Replaced Class Library CheckBoxes with ToggleButton
  • Added Search box to Class Library to allow easy finding of Entity classes
  • Increased scrolling speed when using Drag/Drop on treeview
  • ListView numeric columns are now right-aligned
  • Re-instated “Explore” context-menu option for root Entities
  • Added support for parameterised Methods
  • Window buttons bar is now visible by default (to reduce flickering)
  • Added AddRange & RemoveRange methods to TransientEntityList
  • Added AddRange & RemoveRange methods to EntityList
  • Search Form now shows Query text as query is built
  • Boolean editor now changes value immediately
  • Hitting F2 over a listview opens the editor beneath the mouse cursor
  • ‘Short’ values now have smaller widgets (Numbers, Enums, Dates)
  • Added new “Replace/Add” context-menu items for context sensitive queries
  • “Open File” option renamed to “View File”
  • Changed internal async command processing
  • Added “Allow multi-monitor use” option for non-MDI interfaces
  • Query List no longer shows “Type” in first header
  • Entity treeview no longer scales when window is resized
  • Changed error message when trying to execute HQL using MemoryCache provider

Fixes

  • Reduced flickering when rendering/repainting controls
  • Corrected header style for each window
  • Correction in MyApplication.Start() to allow repeated calls
  • Saving object graphs with unmapped entities now always forces NHibernatePersistence
  • Corrected UI updates when setting Parameters
  • Applied [Visible=false] attribute to all public interface members
  • Exceptions no longer thrown if Providers aren’t defined in app.config
  • Correction in collection/list count
  • Correction in identifying parent widgets
  • Fixed margin settings for collapsible panels
  • Corrected identification/caching of icons for sub-classes
  • Corrected icon for Namespace nodes
  • ListView “Auto-resize” option now overrides user defined widths
  • Window button tooltip is updated for Search Forms
  • Corrected culture setting for DateTimePicker
  • Better handling of exceptions when editor controls are rendered
  • Now uses correct DateTimePicker rendering for Windows 7
  • Corrected background colour in Enum editor
  • Empty Category headers are no longer displayed
  • Disabled “Explore” option for primitive types
  • Corrected multiple argument injection in EntityList Add & Remove methods
  • Reduced Drag/Drop tip flickering
  • ListView “Property” column is now sized to fit
  • Selected TreeView node is now scrolled into view
  • Corrected border colour for Boolean editor
  • Corrected Entity Relationships for properties in super classes
  • Corrected event handler disposal in a few controls

Optimisations

  • Improved string building performance
  • Optimised widget detection at mouse co-ords
  • DynamicMethods are now created lazily
  • Entity Relationships are now resolved lazily

Eric Evans: “What I’ve learned about DDD since the book”

June 30th, 2009

Eric Evans talks about the most essential parts of his book, having practiced it over the last 5 years.

One of the topics that caught my attention was Exploration and Experimentation (3m 25s into the video).  Evans suggests that teams should be exploring & experimenting even after a useful domain model is created.  His quote:

What are the odds that [the first good model] is the best you could have done?

So why aren’t teams doing this already?  Typically, it’s because of fear and cost of change. Traditionally, software has never been easy to change (read expensive).  And for all of the new technology being spewed out, not all of it is designed to make change easy.

This is the void that TrueView attempts to address.  It’s not about UI design, or database design, or Web Service contracts.  It’s about creating interactive domain models that Domain Experts and Software Experts can explore, discuss, and help refine the ubiquitous language.

If you haven’t tried it already, you can download it here. I hope you find it useful.