static void Manual() { var settings = new MySettings { ConnectionString = "Host=localhost" }; var service = new MyService(settings); var service2 = new MyService2(service, settings); service2.Start(); }
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(); }
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(); }
public MyService(MySettings settings) { _settings = settings; }
public MyService2(MyService service, MySettings settings) { _settings = settings; _service = service; }