Autofac Resolve Open Generic Interface with Open Generic Class

社会主义新天地 提交于 2019-12-05 22:15:13

You have to use the RegisterGeneric method see Registration Concepts - Open Generic Components

Something like this should works :

builder.RegisterGeneric(typeof(MyClass<>)).As(typeof(IMyInterface<>)); 

Yes it is trivial with container.RegisterGeneric:

container.RegisterGeneric(typeof(MyClass<>)).As(typeof(IMyInterface <>));

You also seem to have your interface and class switched in the examples in your question. The registration should start with the type to want to register (e.g. MyClass) followed by the type you it to be registered as (e.g. IMyInterface).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!