views:

153

answers:

1

In Structure map I have the following line working with domain events:

public void Dispatch<TEvent>(TEvent eventToDispatch) where TEvent : IDomainEvent
        {
            foreach (var handler in ObjectFactory.GetAllInstances<IDomainEventHandler<TEvent>>())
            {
                if (handler.IsActive)
                    handler.Handle(eventToDispatch);
            }
        }

I am registering these inside a StructureMap Registry like this:

x.AddAllTypesOf(typeof(IDomainEventHandler<>));

The first block above throws an Unknown error - Structure Map Code 400. Does anyone know how I can get specific types of generic class from the strcuture map container?

TIA

Andrew

+2  A: 

The first thing I'd check is what the following outputs:

Console.WriteLine(ObjectFactory.WhatDoIHave());

Make sure that your event handlers are being registered as you expect.

If the classes are registered as you expect, then I think this is how you want to resolve your IDomainEventHandler's:

foreach (var handler in ObjectFactory.ForObject(eventToDispatch)
                                     .GetAllClosedTypesOf(typeof(IDomainEventHandler<>))
                                     .As<IDomainEventHandler<TEvent>>())
Jeremy Wiebe
Thanks, the WhatDoIHave() method lead me to see that the issue was a missing domain event handler for the domain event which I raised. Cheers again
REA_ANDREW