好的,我想创建特定接口的任意实现并解决它们。它实际上与插件系统类似。 “创建自己的interface X实现,应用程序完成其余的工作”
public interface IMenuEntry { ... }
// auto-mapping (registration-by-convention)
_container.RegisterTypes(AllClasses.FromAssemblies(assemblies),
WithMappings.FromMatchingInterface,
// ResolveAll need names for multiple registrations of the same type (?)
WithName.TypeName,
WithLifetime.ContainerControlled);
var g = _container.ResolveAll<IMenuEntry>(); // empty - why?
当我检查我的容器注册时,我的实现是在那里,名称是类的名称 - 而不是接口。精彩。 但为什么我无法解决IMenuEntry
的所有实现?它总是空的。
答案 0 :(得分:3)
我正在查看此post,听起来WithMappings.FromMatchingInterface
只会将名为MenuEntry
的类型与IMenuEntry
匹配。
您可以尝试使用WithMappings.FromAllInterfaces
。