Reputation: 10764
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
Upvotes: 4
Views: 2648
Reputation: 3963
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>>())
Upvotes: 5