After registering an open generic type in Autofac, I got the following error when running the application:
Here is the code I was using to register my MediatR behavior in Autofac:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.Register(typeof(UnitOfWorkBehavior<,>)).As(typeof(IPipelineBehavior<,>)); |
Turns out that if you are using open generics you have to use a different method on the Autofac container builder:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
builder.RegisterGeneric(typeof(UnitOfWorkBehavior<,>)).As(typeof(IPipelineBehavior<,>)); |
More information in the Autofac documentation: https://autofaccn.readthedocs.io/en/latest/register/registration.html#open-generic-components