[英]Resolve an Interface using Unity 2.1
I have a basic class that is trying to resolve an interface using Unity. 我有一个基本类正在尝试使用Unity解析接口。
IUnityContainer containter = new UnityContainer();
containter.RegisterType<IRepositoryFactory>();
IRepositoryFactory repositoryFactory = containter.Resolve<IRepositoryFactory>();
My config file is as follows: 我的配置文件如下:
<unity>
<containers>
<container>
<types>
<type name="IRepositoryFactory"
type="QuinntyneBrown.Interfaces.IRepositoryFactory"
mapTo="QuinntyneBrown.Photography.Factories.RepositoryFactory" />
</types>
</container>
</containers>
</unity>
I'm getting the following error: 我收到以下错误:
Resolution of the dependency failed, type = "QuinntyneBrown.Interfaces.IRepositoryFactory", name = "(none)". 解决依赖关系失败,类型=“ QuinntyneBrown.Interfaces.IRepositoryFactory”,名称=“(none)”。 Exception occurred while: while resolving. 发生以下异常:正在解决。
At the time of the exception, the container was: 在发生异常时,容器为:
Resolving QuinntyneBrown.Interfaces.IRepositoryFactory,(none) 解决QuinntyneBrown.Interfaces.IRepositoryFactory,(无)
containter.RegisterType<IRepositoryFactory>();
This doesn't make any binding. 这没有任何约束力。 Load bindings from your config file instead: 从您的配置文件中加载绑定:
containter.LoadConfiguration();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.