我只是试着用Unity来做基本的DI。这是我的设置:
C#组件项目
public interface ILanguageBindings { ... }C++/CX组件项目
private ref class LanguageBindings : ILanguageBindings { ... }
public ref class LanguageImplementation {
public:
ILanguageBindings GetLanguageBindings();
}C#便携式
public class Bootstrap {
private UnityContainer container;
public void Initialize(ILanguageBindings language) {
this.container.RegisterInstance<ILanguageBindings>(language);
}
}C#应用程序
var languageImpl = new LanguageImplementation();
var languageBindings = languageImpl.GetLanguageBindings();
var bootstrap = new Bootstrap();
bootstrap.Initialize(languageBindings);我从UnityContainer获得以下错误消息:
An exception of type 'System.ArgumentException' occurred in
Microsoft.Practices.Unity.DLL but was not handled in user code
Additional information: The type System.__ComObject cannot be
assigned to variables of type SparkiyEngine.Bindings.Language.ILanguageBindings.我使用的是3.5.1405-prerelease版本(在Windows和Windows上都可以使用)。是否有一种方法可以使它与团结容器一起工作,因为我在项目的其余部分中使用它。如果不是,支持ComObjects的替代方案是什么?
完整代码在GitHub上,我刚刚推了问题代码。
发布于 2014-11-11 12:19:58
通过改变解决
private ref class LanguageBindings : ILanguageBindings { ... }至
public ref class LanguageBindings sealed : ILanguageBindings { ... }https://stackoverflow.com/questions/26417812
复制相似问题