Example #1
0
 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();
        }
Example #3
0
        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()));
        }
Example #4
0
 public OutputController(IDateWriter dateWriter)
 {
     _dateWriter = dateWriter;
 }
 public App(IDateWriter writer, ILoggerFactory loggerFactory)
 {
     _writer        = writer;
     _logger        = loggerFactory.CreateLogger <App>();
     _loggerFactory = loggerFactory;
 }
Example #6
0
 public HomeController(IDateWriter dateWriter, Icalculator calculator, ILogger <HomeController> logger)
 {
     _dateWriter = dateWriter;
     _calculator = calculator;
     _logger     = logger;
 }
Example #7
0
 public DateWriter(IDateWriter dateWriter)
 {
     this.dateWriter = dateWriter;
 }
Example #8
0
 public DateWriter(IDateWriter dateWriter)
 {
     _dateWriter = dateWriter;
 }
 public HomeController(IDateWriter dataWrite,
                       IOutput output)
 {
     this._dataWrite = dataWrite;
     this._output    = output;
 }
Example #10
0
 public ConsoleWriter(IDateWriter _dateWriter)
 {
     DateWriter = _dateWriter; // 构造函数注入
 }
Example #11
0
 public DependentClass(IDateWriter dateWriter)
 {
     _dateWriter = dateWriter;
 }
        public Form1()
        {
            InitializeComponent();

            _dateWriter = InstanceFactory.GetInstance <IDateWriter>();
        }
Example #13
0
 public MyComponent(IOutput logger, IDateWriter reader)
 {
     Console.WriteLine("logger and reader");
 }