static async Task Main(string[] args) { var services = new DiServiceCollection(); //services.RegisterSingleton<RandomGuidGenerator>(); //services.RegisterTransient<RandomGuidGenerator>(); services.RegisterTransient <ISomeService, SomeServiceOne>(); services.RegisterSingleton <IRandomGuidProvider, RandomGuidProvider>(); services.RegisterSingleton <MainApp>(); var container = services.GenerateContainer(); var serviceFirst = container.GetService <ISomeService>(); var serviceSecond = container.GetService <ISomeService>(); var mainApp = container.GetService <MainApp>(); serviceFirst.PrintSomething(); serviceSecond.PrintSomething(); //await mainApp.StartAsync(); }
static void Main(string[] args) { IPrinter printer = new ConsolePrinter(); var services = new DiServiceCollection(); services.RegisterTransient <RandomGuidGenerator>(); services.RegisterSingleton <ISomeExternalService, SomeExternalServiceOne>(); services.RegisterSingleton <IRandomGuidProvider, RandomGuidProvider>(); var container = services.GenerateContainer(); var randomGuidGeneratorServiceFirst = container.GetService <RandomGuidGenerator>(); var randomGuidGeneratorServiceSecond = container.GetService <RandomGuidGenerator>(); var someServiceFirst = container.GetService <ISomeExternalService>(); var someServiceSecond = container.GetService <ISomeExternalService>(); printer.WriteLine("Only service registered transient:"); printer.WriteLine(randomGuidGeneratorServiceFirst.RandomGuid.ToString()); printer.WriteLine(randomGuidGeneratorServiceSecond.RandomGuid.ToString()); printer.WriteLine("\nService and implementation registered singleton:"); printer.WriteLine(someServiceFirst.PrintSomething()); printer.WriteLine(someServiceSecond.PrintSomething()); printer.ReadLine(); }
static void Main(string[] args) { var services = new DiServiceCollection(); // services.RegisterSingleton<RandomGuidGenerator>(); // services.RegisterTransient<RandomGuidGenerator>(); services.RegisterSingleton <IRandomGuidProvider, RandomGuidProvider>(); services.RegisterTransient <ISomeService, SomeService1>(); // services.RegisterSingleton(new RandomGuidGenerator()); var container = services.GenerateContainer(); // var service = container.GetService<RandomGuidGenerator>(); // var service1 = container.GetService<RandomGuidGenerator>(); // Console.WriteLine(service.RandomGuid); // Console.WriteLine(service1.RandomGuid); var service = container.GetService <ISomeService>(); var service2 = container.GetService <ISomeService>(); service.PrintSomething(); service2.PrintSomething(); }
static void Main(string[] args) { var services = new DiServiceCollection(); services.RegisterSingleton <ISomeService, SomeService>(); services.RegisterTransient <IRandomGuidProvider, RandomGuidProvider>(); services.RegisterSingleton <IPrinter, ConsolePrinter>(); var container = services.GenerateContainer(); var serviceFirst = container.GetService <ISomeService>(); var serviceSecond = container.GetService <ISomeService>(); serviceFirst.Print(); serviceSecond.Print(); }
static async Task Main(string[] args) { var services = new DiServiceCollection(); services.RegisterTransient <IIlluminationStrategy, FlatShading>(); services.RegisterTransient <ICameraProvider, CameraProvider>(); services.RegisterTransient <ILightProvider, LightProvider>(); services.RegisterTransient <IRayProvider, RayProvider>(); services.RegisterTransient <IRayTracer, MultiThreadRayTracer>(); services.RegisterTransient <ISceneProvider, SceneProvider>(); services.RegisterSingleton <IApp, App>(); var container = services.GenerateContainer(); var app = container.GetService <IApp>(); await Parser.Default.ParseArguments <CommandLineArgs>(args) .WithParsedAsync(async arguments => { try { await app.Run(arguments.FileName, arguments.Output); } catch (Exception e) { Console.WriteLine(e.Message); } }); }
static void Main(string[] args) { // 1 enregistre les services // 2 génère/instancie les containers // 3 utiliser var services = new DiServiceCollection(); // singleton instancié seulement la première fois //services.RegisterSingleton<RandGuidGenerator>(); //services.RegisterSingleton(new RandGuidGenerator()); // transient instancié à chaque appel //services.RegisterTransient<RandGuidGenerator>(); // avec interfaces /*services.RegisterTransient<ISomeService, SomeServiceOne>(); * services.RegisterTransient<IRandomGuidProvider, RandomGuidProvider>();*/ // interfzces + singelton services.RegisterSingleton <ISomeService, SomeServiceOne>(); services.RegisterSingleton <IRandomGuidProvider, RandomGuidProvider>(); var container = services.GenerateContainer(); var serviceFirst = container.GetService <ISomeService>(); var serviceSecond = container.GetService <ISomeService>(); serviceFirst.PrintSomething(); serviceSecond.PrintSomething(); /*var serviceFirst = container.GetService<RandGuidGenerator>(); * var serviceSecond = container.GetService<RandGuidGenerator>(); * * Console.WriteLine(serviceFirst.RandomGuid); * Console.WriteLine(serviceSecond.RandomGuid);*/ }
static void DependencyInjectionDemo() { var services = new DiServiceCollection(); //services.RegisterSingleton<RandomGuidGenerator>(); //services.RegisterTransient<RandomGuidGenerator>(); services.RegisterSingleton <ISomeService, SomeServiceOne>(); services.RegisterTransient <IRandomGuidProvider, RandomGuidProvider>(); var container = services.GenerateContainer(); var service1 = container.GetService <ISomeService>(); var service2 = container.GetService <ISomeService>(); service1.PrintSomething(); service2.PrintSomething(); }
static void Main(string[] args) { ConsolePrinter consolePrinter = new ConsolePrinter(); //Person person = new Person("Tom", "Surname", 18); //Console.WriteLine(person.GetFormatPerson(2)); //Console.WriteLine(person.GetFormatPerson(22)); //Console.WriteLine(); //Rectangle rectangle = new Rectangle(3, 4, 10, 5); //Console.WriteLine($"P = {rectangle.Perimetr()}"); //Console.Write("Enter n:"); //Int32.TryParse(Console.ReadLine(), out int n); //Console.WriteLine(Enum.GetName(typeof(Month), n)); //Exceptions exceptions = new Exceptions(); //try //{ // exceptions.IndexOutOfRange(); //} //catch(IndexOutOfRangeException ex) //{ // consolePrinter.WriteLine(ex.Message); //} //FileHelper fileHelper = new FileHelper(consolePrinter); //FileLogger fileLogger = new FileLogger(); //try //{ // string data = fileHelper.GetAllFilesByDirectory("d:\\EPAM.NET\\Structs"); // consolePrinter.WriteLine(data); // fileLogger.Save("d:\\EPAM.NET\\Structs\\data.txt", data); //} //catch (DirectoryNotFoundException) //{ // consolePrinter.WriteLine("WRONG DIRECTORY"); //} //consolePrinter.WriteLine(fileHelper.SearchFileByPartialName("dat", @"d:\")); //FileLogger fileLogger = new FileLogger(); //try //{ // int a = 0; // int b = 2 / a; //} //catch (DivideByZeroException ex) //{ // try // { // fileLogger.Error(ex, "some message"); // } // catch(ArgumentException ex2) // { // Console.WriteLine(ex2.Message); // } //}; //try //{ // fileLogger.Debug("Debug Message"); // fileLogger.Info("Info message"); // fileLogger.Fatal("Fatal message"); // fileLogger.Warn("Warn message"); //} //catch (ArgumentException ex) //{ // Console.WriteLine(ex.Message); //}; //Car car = new Car(1,(decimal)32.213, 1000,(decimal)33.213); //List<Car> cars = new List<Car>() //{ // new Car(1,(decimal)32.213, 10), // new Car(2,(decimal)12.213, 100), // new Car(3,(decimal)42.213, 1000), // new Car(4,(decimal)2.213, 1000) //}; //BinarySerialize binarySerialize = new BinarySerialize("cars.dat"); //binarySerialize.Serialize(cars); //binarySerialize.Deserialize(); //XMLSerialize xMLSerialize = new XMLSerialize(); //xMLSerialize.Serialize(cars); //xMLSerialize.Deserialize(); //JSONSerialize jSONSerialize = new JSONSerialize(); //jSONSerialize.Serialize(cars); //Reflection reflection = new Reflection(consolePrinter); //reflection.GetInfoAboutDLL("Logger.dll"); Console.Write("Enter a: "); double x = Double.Parse(Console.ReadLine()); Console.Write("Enter b: "); double y = Double.Parse(Console.ReadLine()); Console.Write("Enter operation: "); char operation = Char.Parse(Console.ReadLine()); ConsoleCalculator consoleCalculator = new ConsoleCalculator(consolePrinter); if (operation == '*') { consolePrinter.WriteLine(consoleCalculator.Calculation(x, y, (x1, y1) => x1 * y1).ToString()); } else if (operation == '+') { consolePrinter.WriteLine(consoleCalculator.Calculation(x, y, (x1, y1) => consoleCalculator.Add(x1, y1)).ToString()); } else if (operation == '/') { try { consolePrinter.WriteLine(consoleCalculator.Calculation(x, y, (x1, y1) => x1 / y1).ToString()); } catch (DivideByZeroException) { throw new DivideByZeroException(); } } else if (operation == '-') { consolePrinter.WriteLine(consoleCalculator.Calculation(x, y, (x1, y1) => x1 - y1).ToString()); } //ExcelReader excelReader = new ExcelReader(consolePrinter); //System.Diagnostics.Stopwatch time = System.Diagnostics.Stopwatch.StartNew(); //Console.WriteLine("Unique"); //var smth = excelReader.GetDataTableFromExcel(1, 2); //foreach (var item in smth) //{ // Console.WriteLine(item); //} //time.Stop(); //consolePrinter.WriteLine($"Spend time on funtion: {time.Elapsed.TotalMilliseconds.ToString()}"); //excelReader.SaveIntoFile(); //FileManager fileManager = new FileManager(consolePrinter); //var dublicates = fileManager.GetDublicateFilesInTwoFolders("D:\\EPAM.NET\\Structs\\TrainingWorkshop\\Training7", // "D:\\EPAM.NET\\Structs\\TrainingWorkshop\\Training5"); //Console.WriteLine("Dublicates in two folders"); //foreach (var item in dublicates) //{ // Console.WriteLine(item); //} //var unique = fileManager.GetUniqueFilesInTwoFolders("D:\\EPAM.NET\\Structs\\TrainingWorkshop\\Training7", // "D:\\EPAM.NET\\Structs\\TrainingWorkshop\\Training5"); //Console.WriteLine("Uniques in two folders"); //foreach (var item in unique) //{ // Console.WriteLine(item); //} //ParallelSum parallelSum = new ParallelSum(consolePrinter, 1000, 1000); //Console.WriteLine(parallelSum.GetParallelSum(5)); var services = new DiServiceCollection(); //services.RegisterSingleton<RandomGuidGenerator>(); //services.RegisterTransient<RandomGuidGenerator>(); //services.RegisterSingleton<ISomeService, SomeServiceOne>(); //services.RegisterTransient<IRandomGuidProvider, RandomGuidProvider>(); // services.RegisterSingleton<MainApp>(); services.RegisterSingleton <ICounter, RandomCounter>(); //services.RegisterSingleton<CounterService>(); var container = services.GenerateContainer(); var serviceFirst = container.GetService <ICounter>(); var serviceSecond = container.GetService <ICounter>(); Console.WriteLine(serviceFirst.Value); //Console.WriteLine(serviceSecond.Value); Console.ReadLine(); }