I want to register a generic delegate that resolves itself at runtime, but I cannot find a way to do this in generics.
For a delegate that looks like this:
public delegate TOutput Pipe<in TInput, out TOutput>(TInput input);
And given a discretely registered delegate that looks like this:
public class AnonymousPipe<TInput, TOutput> { public Pipe<TInput, TOutput> GetPipe(IContext context) {...}
I want to register a function line by line:
builder.RegisterGeneric(typeof(Pipe<,>)).As(ctx => { var typeArray = ctx.RequestedType.GetGenericArguments();
I canโt find a way to provide an implementation of generic as a parameter in Autofac - I can just miss something. I know that I can do this through a shared object or interface, but I want to stick with the ease of the delegate. This makes unit testing super easy when entering this data.
Any thoughts? I have to do discrete registrations at the moment (one type combination and no generics).
source share