Closed PulsarFX closed 2 years ago
This can be done by letting the predicate of your RegisterConditional
check for this. There are basically two options:
IQueryHandler<GetLocalStuffQuery>
was found.For instance:
container.RegisterConditional(typeof(IQueryHandler<>), typeof(WebApiQueryHandler<>), c =>
{
if (c.Handled) return false;
var consumer = c.Consumer.ImplementationType;
var handlerTypes = consumer.GetClosedTypesOf(typeof(IRequestHandler<,>))
.Concat(consumer.GetClosedTypesOf(typeof(IRequestHandler<>)));
var requestMessageTypes = handlerTypes.Select(type => type.GetGenericArguments().First());
var onlyLocalMessageTypes = requestMessageTypes.Where(typeof(IOnlyWorkLocal).IsAssignableFrom);
return !onlyLocalMessageTypes.Any();
// or do if (onlyLocalMessageTypes.Any()) throw new ArchitecturalRulesViolatedException(); return true;
});
This is a very good start, thanks alot. 👍
for reference: I had to insert
if (!c.HasConsumer) { return true; }
before accessing c.Consumer
to prevent InvalidOperationExceptions
This is a question on how to keep Client and Server code separated from each other with the help of SimpleInjector and not have creepy code undermine the code design.
ICommandHandler
andIQueryHandler
.For
Requests
we defined a InterfaceIOnlyWorkLocal
likeclass OpenVisualStudioRequest : IOnlyWorkLocal, IRequest<Process>
Requests with this interface should not be allowed to call the server.Requests are registered with
For server calling we have the generic proxies:
My question is: Is there a way to have SimpleInjector detect and prevent the creation of RequestsHandlers which have a dependency on a WebApiQueryHandler (directly or indirectly)?
A candidate that should throw on
.Verify()
may look like this:Of course there may be queries which won't leave the client, which should not throw on
.Verify()
: