Unity MVC3依赖注入示例源码 程序介绍: 这个类库可以将Microsoft's Unity IoC简单整合到ASP.NET MVC3中。项目包含一个定制的DependencyResolver,为每一个HTTP请求创建一个子容器并且在请求结束时释放所有注册过IDisposable接口的实例。 来自51ASpXA library that allows simple Integration of Microsoft's Unity IoC container with ASP.NET MVC 3. This project includes a bespoke DependencyResolver that creates a child container per HTTP request and disposes of all registered IDisposable instances at the end of the request. 单步执行代码可以看到每一个web请求ExampleContext的构造函数都被执行一次。上下文环境被两个共享: private static IUnityContainer BuildUnityContainer() { var container = new UnityContainer(); container.RegisterType<IUpperCaseService, UpperCaseService>(); container.RegisterType<ILowerCaseService, LowerCaseService>(); container.RegisterType<IExampleContext, ExampleContext>(new HierarchicalLifetimeManager()); return container; } 当请求结束时,ExampleContext的dispose方法被调用,并且所有相关资源被释放。
- 1
- 粉丝: 319
- 资源: 3220
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助