代码改变世界

Microsoft.Extensions.DependencyInjection 阅读笔记

2019-05-10 15:16  咒语  阅读(1590)  评论(0编辑  收藏  举报

一、 关于IServiceCollection接口的设计

 public interface IServiceCollection : IList<ServiceDescriptor>
    {
    }

a. 为什么不直接用List<>集合,而要重新定义一个这样的IServiceCollection接口呢?

1. 为了从IList<>那里得到所有的List集合的可重载方法;
2. 有了自已的名字IServiceCollection,而不是List<>这样直接使用,如果直接继承了List<>的话,那么在使用的时候,你用这个List<>根本就不知道这是干啥的,并且还要带上参数;

 

 二、关于调试时的跟踪

[DebuggerDisplay("Lifetime = {Lifetime}, ServiceType = {ServiceType}, ImplementationType = {ImplementationType}")]
 public class ServiceDescriptor

a. 加上DebuggerDisplay特性,然后用{}把属性名称显出来了即可,在跟踪Stack中你就能看到想要显示的效果了。

 

 

 

 

未完.....