gpt4 book ai didi

c# - Unity - 解决依赖失败(没有注册)

转载 作者:行者123 更新时间:2023-11-30 13:39:05 26 4
gpt4 key购买 nike

我在这行代码中遇到错误:

    using (IMaterialClient rawMaterialServiceProxy =
ServerUtility.Container.Resolve<IMaterialClient>())

错误:

Resolution of the dependency failed... The current type, Xxx, is an interface and cannot be constructed. Are you missing a type mapping?

我没有注册具体的 IMaterialClient。在我刚刚观看的 Pluralsight 视频中,他们说您不必注册每种类型,因为如果没有指定,Unity 会找到一个实现。那改变了吗?我错过了什么吗?为什么不解决?运行时,具有实际 IMaterialClient 实现的程序集位于 bin 文件夹中。

最佳答案

如果他们这样说 Unity,那他们就错了。 Unity 将解析一个具体类型 ( .Resolve<MyClass> ),但接口(interface)必须通过将它们与具体类型相关联来显式注册。

还有Unity Auto Registration等扩展名提供这些功能;我没有使用它们的经验。

关于c# - Unity - 解决依赖失败(没有注册),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13752427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com