I may well be missing something obvious here; but if I have the following:
public interface IRequest<out T>
where T : class
{
T Request
{
get;
}
}
And:
public interface IResponse<out T>
where T : class
{
T Response
{
get;
}
}
And then a third interface which uses these interfaces as generic type parameters:
public interface IResponder<in TRequest, TRequestValue, out TResponse, TResponseValue>
where TRequest : IRequest<TRequestValue>
where TResponse : IResponse<TResponseValue>
where TRequestValue : class
where TResponseValue : class
{
TResponse Query(TRequest request);
}
Is there a way to avoid having to pass through TRequestValue
and TResponseValue
as generic parameters to IResponder
(and therefore avoid having to duplicate the associated constraints)?
Essentially I'd prefer to have something similar to the following to reduce the number of generic type parameters to IResponder
(I realise this wouldn't compile at the moment):
public interface IResponder<in TRequest, out TResponse>
where TRequest : IRequest
where TResponse : IResponse
{
TResponse Query(TRequest request);
}
The only way I can think of doing this would be to write two non-generic interfaces (IRequest
and IResponse
) and then make IRequest<T>
and IResponse<T>
implement those, but that seems wrong in some way.
I'm fully aware that I may have hit this problem because of the way I'm doing things here, so please feel free to suggest what I'm doing wrong!
Note: The whole Request, Response, Responder example isn't actually the code I'm writing, but rather an example to try and support my question.