用Unity实现层与层之间的接口调用

C# 2022-02-11 14:39:41

namespace Dawn.HIS.MVC.CommonSupport
{
public class UnityControllerFactory : DefaultControllerFactory
{
private readonly IUnityContainer container;

public UnityControllerFactory(IUnityContainer container)
{
//要做异常处理
this.container = container;
}
protected override IController GetControllerInstance(Type controllerType)
{       //这里把Controller实例注册到了unity容器
IController icontroller = container.Resolve(controllerType) as IController;
return icontroller;
}
}
}