How would I go about of telling unity that the first IRegisterAutoMapper should be of type RegisterAutoMapper and the second of type RegisterAutoMapperMobile ?推荐答案您可以使用 IRegisterAutoMapper 的多个命名映射并结合一个 InjectionConstructor 来实现,该 InjectionConstructor 告诉 Unity 为每个参数使用哪些特定映射.You can do it with multiple named mappings for IRegisterAutoMapper combined with an InjectionConstructor telling Unity what specific mappings to use for each argument.IUnityContainer container = new UnityContainer() .RegisterType<IRegisterAutoMapper, RegisterAutoMapper>() //default .RegisterType<IRegisterAutoMapper, MobileRegisterAutoMapper>("Mobile") .RegisterType<AutoMapperRegisterFactory>( new InjectionConstructor( typeof(IRegisterAutoMapper), new ResolvedParameter<IRegisterAutoMapper>("Mobile"))); 这篇关于用Unity实例化同一个类中同一个接口的两个对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-02 04:06