Exemple #1
0
        static void Manual()
        {
            var settings = new MySettings {
                ConnectionString = "Host=localhost"
            };

            var service = new MyService(settings);

            var service2 = new MyService2(service, settings);

            service2.Start();
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Console.WriteLine("Loading settings...");
            MySettings settings = MySettings.Load();

            Console.WriteLine("MyNumber = {0}", settings.MyNumber);
            Console.WriteLine("MyString = {0}", settings.MyString);

            Console.WriteLine();
            Console.WriteLine("Updating settings and saving files");
            settings.MyNumber++;
            settings.MyString = DateTime.Now.ToString();
            settings.Save();
        }
Exemple #3
0
        static void Main(string[] args)
        {
            var collection = new ServiceCollection();
            var settings   = new MySettings {
                ConnectionString = "Host=127.0.0.1"
            };

            collection.AddSingleton(settings);
            collection.AddSingleton <MyService>();
            collection.AddSingleton <MyService2>();

            var provider   = collection.BuildServiceProvider();
            var myService2 = provider.GetService <MyService2>();

            myService2.Start();
        }
Exemple #4
0
 public MyService(MySettings settings)
 {
     _settings = settings;
 }
Exemple #5
0
 public MyService2(MyService service, MySettings settings)
 {
     _settings = settings;
     _service  = service;
 }