06-001 DependencyInjection 之 LifecycleKind
2015-03-20 16:57
197 查看
IApplicationBuilder 里有如下一成员:
HttpContext 里有如下两个成员:
IServiceProvider 的成员:
创建 添加 调用的简单代码如下:
简单描述为:创建一个集合 ServiceCollection;向集合里添加 键值对:接口 和 接口的实现。
集合会生成 ServiceProvider. 通过 ServiceProvider 来得到需要的对象。
代码中的 .AddTransient 作何理解吗? 现在看一下 LifecycleKind
IServiceProvider ApplicationServices { get; set; }
HttpContext 里有如下两个成员:
public abstract IServiceProvider ApplicationServices { get; set; } public abstract IServiceProvider RequestServices { get; set; }
IServiceProvider 的成员:
public object GetService(Type serviceType)
创建 添加 调用的简单代码如下:
var serviceProvider = new ServiceCollection() .AddTransient<IFakeService, FakeService>() .AddTransient<CreationCountFakeService>() .BuildServiceProvider(); var IFakeService = serviceProvider.GetService(typeof(IFakeService))() as IFakeService;
简单描述为:创建一个集合 ServiceCollection;向集合里添加 键值对:接口 和 接口的实现。
集合会生成 ServiceProvider. 通过 ServiceProvider 来得到需要的对象。
代码中的 .AddTransient 作何理解吗? 现在看一下 LifecycleKind
public enum LifecycleKind { Singleton, //单例;单态; 只有一个示例 每次调用都返回同一个对象 Scoped, // 一定范围的 在一定范围内只有一个实例 如在一个请求范围内是同一个实例 不同的请求创建新对象 Transient //短暂的;转瞬即逝的;临时的 每次调用都创建一个新的对象 }
相关文章推荐
- Maven异常_06_ Unknown lifecycle phase "mvn"
- Multiple annotations found at this line: - Plugin execution not covered by lifecycle configuration:
- Managing the Activity Lifecycle
- ALM(application lifecycle management)应用程序生命周期管理
- [Midterm1]Software Development Lifecycle
- ActivityLifecycleCallbacks使用方法初探
- Customer segmentation – LifeCycle Grids with R(转)
- maven 问题 Plugin execution not covered by lifecycle configuration: org.apache.maven.plugins:maven-res
- flume启动No appenders could be found for logger (org.apache.flume.lifecycle.LifecycleSupervisor)
- 在POM配置Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”的解决方案
- Preparing for Application and Service Deployment-Application Life Cycle Management for Windows Azure
- Maven - Build Life Cycle
- Flex Component instantiation life cycle | Flex组件实例化生命周期
- UIViewController of lifecycle
- Plugin execution not covered by lifecycle conf
- 在POM配置Maven plugin提示错误“Plugin execution not covered by lifecycle configuration”的解决方案
- unity3d中脚本生命周期(MonoBehaviour lifecycle)
- Plugin execution not covered by lifecycle configuration
- tomcat lifecycle exception
- 神奇的ActivityLifecycleCallbacks,解决Activity管理的后顾之忧