- 51Aspx源码必读.txt[2KB]
- .gitignore[94B]
- from.gif[4KB]
- Unity.Mvc3.sln[1KB]
- Unity.Mvc3.suo[47KB]
- 最新Asp.Net源码下载.url[123B]
源码介绍
源码参数
Unity MVC3依赖注入示例源码
程序介绍:
这个类库可以将Microsoft's Unity IoC简单整合到ASP.NET MVC3中。项目包含一个定制的DependencyResolver,为每一个HTTP请求创建一个子容器并且在请求结束时释放所有注册过IDisposable接口的实例。
A 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方法被调用,并且所有相关资源被释放。
下载记录(Only Recent 100)
用户名 | 推荐指数 | 下载时间 |
---|