Skip to content

Instantly share code, notes, and snippets.

@ashic
Created February 1, 2012 16:53
Show Gist options
  • Save ashic/1718000 to your computer and use it in GitHub Desktop.
Save ashic/1718000 to your computer and use it in GitHub Desktop.
public class SomeCommandHandler
{
public SomeCommandhandler(uow){_uow = uow};
public void Handle(SomeCommand command)
{
}
}
public class UoWWrapper
{
public UoWWrapper(Func<UoW, Action<object>> nextFactory)
{
_nextFactory = nextFactory;
}
public void Handle(object command)
{
var uow = new UoW()
{
var handler = nextFactory(uow);
handle(command);
uow.Commit();
}
}
}
public class CompositionRoot
{
public void Setup()
{
var bus = new Bus();
Func<UoW, Action<object>> someHandlerFactory = uow => new SomeCommandHandler(uow).Handle;
var wrapped = new UoWWrapper(someHandlerFactory).Handle;
bus.RegisterCommand<SomeCommand>(wrapped);
}
}
//Some widening - narrowing may be needed between Action<T> and Action<object> but that's trivial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment