private static void WriteDate() { // Create the scope, resolve your IDateWriter, // use it, then dispose of the scope. using (ILifetimeScope scope = Container.BeginLifetimeScope()) { IDateWriter writer = scope.Resolve <IDateWriter>(); writer.WriteDate(); } }
public static void Main(string[] args) { RegisterServices(); AsyncMessageWriter asyncMessageWriter = new AsyncMessageWriter(ServiceLocator.Current.GetService <ILogger <AsyncMessageWriter> >()); asyncMessageWriter.WriteMessage("Here is a test message.").Wait(100); IDateWriter writer = ServiceLocator.Current.GetService <IDateWriter>(); writer.WriteDate(); }
public static void WriteDate() { ILogger logger2 = Container.Resolve <ILogger>(); logger2.ShowInConsole(string.Format("begin write date: {0}", logger2.GetHashCode())); // Create the scope, resolve your IDateWriter, // use it, then dispose of the scope. using (var scope = Container.BeginLifetimeScope()) { var writer = scope.Resolve <IDateWriter>(); writer.WriteDate(); logger2.ShowInConsole(string.Format("write date instance 1: {0}", writer.GetHashCode())); } IDateWriter writer2 = Container.Resolve <IDateWriter>(); logger2.ShowInConsole(string.Format("write date instance 2: {0}", writer2.GetHashCode())); }
public OutputController(IDateWriter dateWriter) { _dateWriter = dateWriter; }
public App(IDateWriter writer, ILoggerFactory loggerFactory) { _writer = writer; _logger = loggerFactory.CreateLogger <App>(); _loggerFactory = loggerFactory; }
public HomeController(IDateWriter dateWriter, Icalculator calculator, ILogger <HomeController> logger) { _dateWriter = dateWriter; _calculator = calculator; _logger = logger; }
public DateWriter(IDateWriter dateWriter) { this.dateWriter = dateWriter; }
public DateWriter(IDateWriter dateWriter) { _dateWriter = dateWriter; }
public HomeController(IDateWriter dataWrite, IOutput output) { this._dataWrite = dataWrite; this._output = output; }
public ConsoleWriter(IDateWriter _dateWriter) { DateWriter = _dateWriter; // 构造函数注入 }
public DependentClass(IDateWriter dateWriter) { _dateWriter = dateWriter; }
public Form1() { InitializeComponent(); _dateWriter = InstanceFactory.GetInstance <IDateWriter>(); }
public MyComponent(IOutput logger, IDateWriter reader) { Console.WriteLine("logger and reader"); }