Scott,
I'd like to first say that this book has alone taken my development to a whole new level. FINALLY, someone has the time to explain IMPLEMENTATION from a .NET point of view instead of just blogging about DDD and providing no implementation... so thanks for writing a GREAT book.
I hope to see a 2nd version, or another book along the same lines as DDD and Enterprise Architecture become more widely adopted by the .NET community.
So, on to my question.
On pg. 617, you introduce a basic framework for handling Domain Events. You credit Udi Dahan with the framework, but I believe the implementation is your own.
The most recent info I can find on Udi's blog about this is here:
http://www.udidahan.com/2009/06/14/d...nts-salvation/
with, or course, no implementation on his end ;)
I tried extracting the framework from the final Agathas Storefront code download for Chapter 14 (the .NET 4.0 version), and brought it into a new project just to see if I could play with the framework a bit, and to see if this framework is something I could use on an existing project.
It seems the one thing that is not working for me is the Setter Injection in for the DomainEventHandlerFactory property in the DomainEvents class.
the Bootstrapper file looks like it correctly sets the dependency of that property to a concrete object:
Code:
ForRequestedType<IDomainEventHandlerFactory>().TheDefault.Is.OfConcreteType<StructureMapDomainEventHandlerFactory>();
when I hit code that calls the .RaiseEvents method of the static DomainEvents class, the DomainEventHanlderFactory is always null.
For example, in my test project, I have a OrderService class that has a Create method that takes an Order:
Code:
public void Create(Order order)
{
DomainEvents.Raise(new OrderSubmittedEvent() { Order = order });
}
this should look very familiar, as it's pretty much a call I took from Agatha's.
I can see what StructureMap has by calling "ObjectFactory.WhatDoIHave()", and it has an instance of StructureMapDomainEventHandlerFactory for IDomainEventHandlerFactory definition.
But again, even with StructureMap telling me it has an implementation for the DomainEvents.DomainEventHandlerFactory, when I go to call Raise in the DomainEvents class, DomainEventHandlerFactory is null.
If i add an explicit assignment in the OrderService class to DomainEventHandlerFactory like this:
Code:
public void Create(Order order)
{
DomainEvents.DomainEventHandlerFactory = new StructureMapDomainEventHandlerFactory();
DomainEvents.Raise(new OrderSubmittedEvent() { Order = order });
}
everything works, which means my problem is directly related to how StructureMap is working with the Setter Injection of DomainEventHandlerFactory in the DomainEvents static class.
Now, I'm working with StructureMap 2.6.x, and I know the book must have been written with the StructureMap 2.5.x version, but I don't think that should make a difference.
Any tips/pointers about what I could potentially be missing here?
Thanks so much!,
Mike