Open kevin-mcmanus opened 3 months ago
Hi,
Currently, there is no way to do this. Nevertheless, if your use case is dependent on this you can always delegate the object instance resolution during the middleware invocation (although not ideal). Something like this:
public class MyMessageHandler<T> : IMessageHandler<T> where T : class
{
private readonly IDependencyResolver _resolver;
public MyMessageHandler(IDependencyResolver resolver)
{
_resolver = resolver;
}
public Task Handle(IMessageContext context, T message)
{
var options = message is Tx ? _resolver.Resolve<MyOptions>() : new MyOptions();
return Task.CompletedTask;
}
}
Is your request related to a problem you have?
I have a generic message handler e.g.
public class MyMessageHandler<T> : IMessageHandler<T>
.MyMessageHandler<T>
has a constructor with some parameters. e.g.public MyMessageHandler(MyOptions options)
If we register
MyOptions
in the DI container, all instances of aMyMessageHandler<T>
for differing typesT
will get the sameMyOptions
injected.It would be good to enable
MyMessageHandler<Tx>
to be injected with a different set of options toMyMessageHandler<Ty>
.Describe the solution you'd like
Open to suggestions. Perhaps something like:
Are you able to help bring it to life and contribute with a Pull Request?
No
Additional context
No response