十年河东,十年河西

莫欺少年穷

NetCore中依赖注入无处不在,关于依赖注入的好处,想必大家都能想到二个字:解耦

但依赖注入是如何做到解耦的呢?

下面以具体实例来描述,如下:

首先,在项目中创建一个发送消息的接口及实现类

    public interface IMessage
    {
        string SendMessage();
    }

    /// <summary>
    /// 传真发送消息类
    /// </summary>
    public class MessageService_ChuanZhen:IMessage
    {
        public string SendMessage()
        {
            return "90年代的我使用传真发送消息";
        }
    }
View Code

相关文章:

  • 2021-12-03
  • 2021-11-24
  • 2022-12-23
  • 2021-07-24
  • 2021-12-17
  • 2021-08-21
猜你喜欢
  • 2021-08-08
  • 2022-03-06
  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-07-08
相关资源
相似解决方案