public interface IQuery<out TResult>
{
}
public interface IQueryHandler<TQuery, TResult> where TQuery : IQuery<TResult>
{
TResult Handle(TQuery query);
}
public class CqrsDispatcher : ICqrsDispatcher()
{
TResult QueryThatResolves<TQuery, TResult>(TQuery query) where TQuery : IQuery<TResult>
{
var handler = _container.Resolve<IQueryHandler<TQuery, TResult>>();
return handler.Handle(query);
}
TResult QueryThatDoesntResolve<TResult>(IQuery<TResult> query)
{
var handler = _container.Resolve<IQueryHandler<IQuery<TResult>, TResult>>();
return handler.Handle(query);
}
}
var query = new SomeQuery();
var thisWorks = _dispatcher.QueryThatResolves<SomeQuery, SomeResult>(query);
var thisDoesnt = _dispatcher.QueryThatDoesntResolve(query);
config.Scan(scanner =>
{
scanner.AssemblyContainingType<StructureMapContainer>();
scanner.WithDefaultConventions();
scanner.AddAllTypesOf(typeof(IQueryHandler<,>));
scanner.AddAllTypesOf(typeof(ICommandHandler<>));
});
config.Scan(scanner =>
{
scanner.AssemblyContainingType<StructureMapContainer>();
scanner.WithDefaultConventions();
scanner.ConnectImplementationsToTypesClosing(typeof(IQueryHandler<,>));
scanner.ConnectImplementationsToTypesClosing(typeof(ICommandHandler<>));
});
--
You received this message because you are subscribed to the Google Groups "structuremap-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to structuremap-us...@googlegroups.com.
To post to this group, send email to structure...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/structuremap-users/6262aa15-2ce4-40bc-b607-e5f112c9af2f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.