上面是依赖注入的所有内容 。
3.如何编写一个简单的依赖注入容器//容器和示例的完整代码如下 public interface ILogWriter { void Write(string text); } public class MyLogWriter : ILogWriter { public void Write(string str) { Console.WriteLine(str); } } public interface ILogger { void Log(string message); } public class MyLogger : ILogger { ILogWriter _writer; public MyLogger(ILogWriter writer) { _writer = writer; } public void Log(string message) { _writer.Write("[ Log ] " + message); } } static void Main(string[] args) { var container = new Container(); container.Register(); container.Register(); var logger = container.Resolve(); logger.Log("asdasdas"); } public class Container { private IDictionary, IList>> Factories { get; set; } public Container() { Factories = new Dictionary, IList>>(); } private Func