首页 新闻 会员 周边 捐助

如何通过unity实现ashx的依赖注入

0
悬赏园豆:5 [待解决问题]

最近在用unity的依赖注入,但是园中类似UnityDependencyResolver 实现 IDependencyResolver的方式只能实现控制器的依赖注入,而ashx的就不行,无效,问问园中的大牛们可有良方啊?

以下是控制器依赖注入的实现代码,因为代码以复制到html格式上去就报错,所以直接以这样的形式贴出来了:

protected void Application_Start()
{

IUnityContainer container = GetUnityContainer();

 

DependencyResolver.SetResolver(new UnityDependencyResolver(container));
AreaRegistration.RegisterAllAreas();

RegisterGlobalFilters(GlobalFilters.Filters);
RegisterRoutes(RouteTable.Routes);

}

private IUnityContainer GetUnityContainer()
{

IUnityContainer container = new UnityContainer();
container.RegisterType<IRep_kk, Rep_kk>();接口和实现类

return container;
}

public class UnityDependencyResolver : IDependencyResolver
{
IUnityContainer container;
public UnityDependencyResolver(IUnityContainer container)
{
this.container = container;
}

public object GetService(Type serviceType)
{
try
{

return container.Resolve(serviceType);
}
catch
{
return null;
}
}

public IEnumerable<object> GetServices(Type serviceType)
{
try
{


return container.ResolveAll(serviceType);
}
catch
{
return new List<object>();
}
}
}

flyjonson的主页 flyjonson | 初学一级 | 园豆:103
提问于:2013-08-19 14:47
< >
分享
所有回答(1)
0

http://www.cnblogs.com/stwyhm/archive/2006/08/09/471765.html

实现 IHttpHandlerFactory ,你就可以用 Unity 了。

Launcher | 园豆:45050 (高人七级) | 2013-08-19 15:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册