Unity 容器无法解析我的类型
我正在从事一个使用 Unity 的项目。第一个元素已经在 web.config 中并且正在正确解析。第二个(IEventRepository)是我添加的。它不会解析类型并引发错误(“依赖关系解析失败..”)
我对此有两个问题: 1)问题是什么? 2)为什么第一个有逗号?
谢谢
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Demo.IPerson, Demo.Shared.Facilities" mapTo="Person, Demo.Shared.Facilities" />
<register type="Web.Repositories.IEventRepository" mapTo="Web.Repositories.MockEventRepository" />
</container>
</unity>
I am working in a project that is using unity. The first element was already in the web.config and is resolving correctly. The second one (IEventRepository) was added by me. It will not resolve the type and throws an error ("Resolution of the dependency failed..")
I have 2 questions on this:
1) What is the issue?
2) Why does the first one have commas in it?
Thanks
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<container>
<register type="Demo.IPerson, Demo.Shared.Facilities" mapTo="Person, Demo.Shared.Facilities" />
<register type="Web.Repositories.IEventRepository" mapTo="Web.Repositories.MockEventRepository" />
</container>
</unity>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
逗号的目的是分隔类型和组件。例如,第一行中的 Demo.IPerson 是类型,该类型位于 Demo.Shared.Facilities 程序集中。在第二行中,您没有指定类型和程序集,这可能是错误的原因。
如果您定义了类型别名,则第 2 行中配置注册的方式可以起作用。查看Unity 配置架构< /a>
The purpose of the commas is to separate the Type and Assembly. For example, in the first line Demo.IPerson is the Type and this type is in the Demo.Shared.Facilities assembly. In the second line you haven't specified both the Type and Assembly which could be the reason for the error.
The way you have configured the registration in line 2 could work if you have defined a type alias. Have a look at The Unity Configuration Schema