首页 新闻 赞助 找找看

Unity 的配置文件啥时候生效,怎么知道是配置文件错了,还是根本就没读配置文件?

0
悬赏园豆:10 [已解决问题] 解决于 2013-12-10 22:12

Dim myContainer As New UnityContainer

Dim myHelloWorld As IHelloWorld = myContainer.Resolve(Of IHelloWorld)()

MessageBox.Show(myHelloWorld.SayHello())

执行到第二句就出错了,告诉我:

Resolution of the dependency failed, type = "Demo.Interface.IHelloWorld", name = "(none)".
Exception occurred while: while resolving.
Exception is: InvalidOperationException - The current type, Demo.Interface.IHelloWorld, is an interface and cannot be constructed. Are you missing a type mapping?

 

我的app.config文件如下:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<section name="unity" type="Microsoft.Practices.Unity.Configuration.UnityConfigurationSection, Microsoft.Practices.Unity.Configuration"/>
</configSections>
<unity xmlns="http://schemas.microsoft.com/practices/2010/unity">
<alias alias="IHelloWorld" type="Demo.Interface.IHelloWorld, Demo.Interface" />
<namespace name="Demo.Interface" />
<assembly name="Demo.Interface" />
<container>
<register type="IHelloWorld" mapTo="Demo.Instance.MyHelloWorld, Demo.Instance" />
</container>
</unity>
<startup>
<supportedRuntime version="v2.0.50727" />
</startup>
</configuration>

 

补充:

Demo.Interface.dll文件里面是Demo.Interface.IHelloWorld

Demo.Instance.dll文件里面是实现 Demo.Instance.MyHelloWorld

我的主程序是Demo.Unity.exe

爱编程的大叔的主页 爱编程的大叔 | 高人七级 | 园豆:30839
提问于:2013-12-10 16:38
< >
分享
最佳答案
0

UnityContainer.LoadConfiguration

Unity 的帮助文档上有,你应该先看看。

收获园豆:10
Launcher | 高人七级 |园豆:45045 | 2013-12-10 16:52

Microsoft的实例也是坑人,所有Google到的代码都是显式声明。

LoadConfiguration居然在另外一个DLL里面。

你虽然说得不清不楚,不过给了点提示,谢谢。

爱编程的大叔 | 园豆:30839 (高人七级) | 2013-12-10 22:11
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册