首页 新闻 赞助 找找看

.net开发框架注册时采用Unity时报错 Resolution of the dependency failed

0
悬赏园豆:15 [已关闭问题] 关闭于 2015-03-31 10:42

最近看到很多关unity的贴子,所以决定将自己使用的开发框架进行调整,改成使用unity方式注册调用,但在实际的使用过程中出现了一些问题,特上来向前辈们请教

一、项目结构

采用原始的三层+EF,结构为IBLL,BLL,IDAL、DAL,抽象类实现接口中的方法,采用BLL下的BASEBLL实现IBLL中的接口(DAL和IDAL层相同),然后专门建立DALFactory进行注入(unity)

二、问题

在BLL层具体的类中对接口进行Resolve 的时候出错,代码如下:

[InjectionConstructor]
public CityBLL()
{
dal = container.Resolve<ICityDAL>();
baseDAL = dal;
}
[InjectionConstructor]
public CityBLL(ICityDAL dal)
: base(dal)
{
this.dal = dal;
}

以上红色字体是出问题的地方

另外看到有同学提到构造函数要用InjectionConstructor属性,但我加上后还是无效

报错的内容:

Resolution of the dependency failed, type = "IDAL.ICityDAL", name = "(none)".

Exception occurred while: while resolving.

Exception is: InvalidOperationException - The current type,

问题补充:

Factory中的代码

public class DALFactory
{
//普通局部变量
private static Hashtable objCache = new Hashtable();
private static object syncRoot = new Object();
private static DALFactory m_Instance = null;

/// <summary>
/// IOC的容器,可调用来获取对应接口实例。
/// </summary>
[Dependency]
public IUnityContainer Container { get; set; }

/// <summary>
/// 创建或者从缓存中获取对应业务类的实例
/// </summary>
public static DALFactory Instance
{
get
{
if (m_Instance == null)
{
lock (syncRoot)
{
if (m_Instance == null)
{
m_Instance = new DALFactory();
//初始化相关的注册接口
m_Instance.Container = new UnityContainer();

//手工加载
m_Instance.Container.RegisterType<ICityDAL, CityDAL>();

}
}
}
return m_Instance;
}
}

beggar_的主页 beggar_ | 初学一级 | 园豆:10
提问于:2015-03-27 19:58
< >
分享
所有回答(2)
0

你的代码中,标红的container是哪里来的?

| 园豆:780 (小虾三级) | 2015-03-28 17:36
0

似乎是wpf啊

星星点灯6 | 园豆:164 (初学一级) | 2015-03-29 16:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册