十年河东,十年河西
莫欺少年穷
NetCore中依赖注入无处不在,关于依赖注入的好处,想必大家都能想到二个字:解耦
但依赖注入是如何做到解耦的呢?
下面以具体实例来描述,如下:
首先,在项目中创建一个发送消息的接口及实现类
public interface IMessage { string SendMessage(); } /// <summary> /// 传真发送消息类 /// </summary> public class MessageService_ChuanZhen:IMessage { public string SendMessage() { return "90年代的我使用传真发送消息"; } }