diff --git a/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/.gitignore b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/.gitignore new file mode 100644 index 0000000..26023e0 --- /dev/null +++ b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/.gitignore @@ -0,0 +1,15 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Rider ignored files +/modules.xml +/projectSettingsUpdater.xml +/contentModel.xml +/.idea.HomeWork5-Solid.iml +# Ignored default folder with query files +/queries/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# Editor-based HTTP Client requests +/httpRequests/ diff --git a/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/indexLayout.xml b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/indexLayout.xml new file mode 100644 index 0000000..7b08163 --- /dev/null +++ b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/indexLayout.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/vcs.xml b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/HomeWork5-Solid/.idea/.idea.HomeWork5-Solid/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/HomeWork5-Solid/HomeWork5-Solid.sln b/HomeWork5-Solid/HomeWork5-Solid.sln new file mode 100644 index 0000000..d94ed92 --- /dev/null +++ b/HomeWork5-Solid/HomeWork5-Solid.sln @@ -0,0 +1,34 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question1", "Question1\Question1.csproj", "{6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question2", "Question2\Question2.csproj", "{05647A34-C5CA-4C64-A73C-A74A55B06BA5}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question3", "Question3\Question3.csproj", "{CA6358D6-57D4-4B19-A3C1-4987DEEF156C}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Question4", "Question4\Question4.csproj", "{E6524682-AE0F-449E-8531-A11D92955845}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6D6AFD49-DEE5-4ED9-B6A7-934D7F3259E6}.Release|Any CPU.Build.0 = Release|Any CPU + {05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {05647A34-C5CA-4C64-A73C-A74A55B06BA5}.Release|Any CPU.Build.0 = Release|Any CPU + {CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CA6358D6-57D4-4B19-A3C1-4987DEEF156C}.Release|Any CPU.Build.0 = Release|Any CPU + {E6524682-AE0F-449E-8531-A11D92955845}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E6524682-AE0F-449E-8531-A11D92955845}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E6524682-AE0F-449E-8531-A11D92955845}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E6524682-AE0F-449E-8531-A11D92955845}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/HomeWork5-Solid/Question1/Program.cs b/HomeWork5-Solid/Question1/Program.cs new file mode 100644 index 0000000..e5dff12 --- /dev/null +++ b/HomeWork5-Solid/Question1/Program.cs @@ -0,0 +1,3 @@ +// See https://aka.ms/new-console-template for more information + +Console.WriteLine("Hello, World!"); \ No newline at end of file diff --git a/HomeWork5-Solid/Question1/Question1.csproj b/HomeWork5-Solid/Question1/Question1.csproj new file mode 100644 index 0000000..6c1dc92 --- /dev/null +++ b/HomeWork5-Solid/Question1/Question1.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/HomeWork5-Solid/Question1/answer.pdf b/HomeWork5-Solid/Question1/answer.pdf new file mode 100644 index 0000000..ace93ed Binary files /dev/null and b/HomeWork5-Solid/Question1/answer.pdf differ diff --git a/HomeWork5-Solid/Question2/Program.cs b/HomeWork5-Solid/Question2/Program.cs new file mode 100644 index 0000000..609d0d8 --- /dev/null +++ b/HomeWork5-Solid/Question2/Program.cs @@ -0,0 +1,68 @@ +using System; +using System.Collections.Generic; + +public interface IProductRepository +{ + List GetProducts(); +} + +public class DatabaseProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "Database Product 1", "Database Product 2" }; + } +} + +public class ApiProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "API Product 1", "API Product 2" }; + } +} + +public class FileProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "File Product 1", "File Product 2" }; + } +} + +public class ProductDisplay +{ + private readonly IProductRepository _repository; + + public ProductDisplay(IProductRepository repository) + { + _repository = repository; + } + + public void Display() + { + List products = _repository.GetProducts(); + foreach (var product in products) + { + Console.WriteLine(product); + } + } +} + +class Program +{ + static void Main() + { + IProductRepository dbRepo = new DatabaseProductRepository(); + ProductDisplay display1 = new ProductDisplay(dbRepo); + display1.Display(); + + IProductRepository apiRepo = new ApiProductRepository(); + ProductDisplay display2 = new ProductDisplay(apiRepo); + display2.Display(); + + IProductRepository fileRepo = new FileProductRepository(); + ProductDisplay display3 = new ProductDisplay(fileRepo); + display3.Display(); + } +} \ No newline at end of file diff --git a/HomeWork5-Solid/Question2/Question2.csproj b/HomeWork5-Solid/Question2/Question2.csproj new file mode 100644 index 0000000..6c1dc92 --- /dev/null +++ b/HomeWork5-Solid/Question2/Question2.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/HomeWork5-Solid/Question3/Program.cs b/HomeWork5-Solid/Question3/Program.cs new file mode 100644 index 0000000..503c798 --- /dev/null +++ b/HomeWork5-Solid/Question3/Program.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; + +public interface IProductRepository +{ + List GetProducts(); +} + +public class DatabaseProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "Database Product 1", "Database Product 2" }; + } +} + +public class ApiProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "API Product 1", "API Product 2" }; + } +} + +public class FileProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "File Product 1", "File Product 2" }; + } +} + +public static class ProductRepositoryFactory +{ + public static IProductRepository CreateRepository(string sourceType) + { + switch (sourceType.ToLower()) + { + case "database": + return new DatabaseProductRepository(); + case "api": + return new ApiProductRepository(); + case "file": + return new FileProductRepository(); + default: + throw new ArgumentException("Invalid source type specified."); + } + } +} + +public class ProductDisplay +{ + private readonly IProductRepository _repository; + + public ProductDisplay(IProductRepository repository) + { + _repository = repository; + } + + public void Display() + { + List products = _repository.GetProducts(); + foreach (var product in products) + { + Console.WriteLine(product); + } + } +} + +class Program +{ + static void Main() + { + string configSource = "api"; + + IProductRepository repository = ProductRepositoryFactory.CreateRepository(configSource); + + ProductDisplay display = new ProductDisplay(repository); + display.Display(); + } +} \ No newline at end of file diff --git a/HomeWork5-Solid/Question3/Question3.csproj b/HomeWork5-Solid/Question3/Question3.csproj new file mode 100644 index 0000000..6c1dc92 --- /dev/null +++ b/HomeWork5-Solid/Question3/Question3.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + + diff --git a/HomeWork5-Solid/Question4/Program.cs b/HomeWork5-Solid/Question4/Program.cs new file mode 100644 index 0000000..ecb555d --- /dev/null +++ b/HomeWork5-Solid/Question4/Program.cs @@ -0,0 +1,67 @@ +using System; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; + +public interface IProductRepository +{ + List GetProducts(); +} + +public class DatabaseProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "Database Product 1", "Database Product 2" }; + } +} + +public class ApiProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "API Product 1", "API Product 2" }; + } +} + +public class FileProductRepository : IProductRepository +{ + public List GetProducts() + { + return new List { "File Product 1", "File Product 2" }; + } +} + +public class ProductDisplay +{ + private readonly IProductRepository _repository; + + public ProductDisplay(IProductRepository repository) + { + _repository = repository; + } + + public void Display() + { + List products = _repository.GetProducts(); + foreach (var product in products) + { + Console.WriteLine(product); + } + } +} + +class Program +{ + static void Main() + { + var serviceCollection = new ServiceCollection(); + + serviceCollection.AddTransient(); + serviceCollection.AddTransient(); + + var serviceProvider = serviceCollection.BuildServiceProvider(); + + var display = serviceProvider.GetRequiredService(); + display.Display(); + } +} \ No newline at end of file diff --git a/HomeWork5-Solid/Question4/Question4.csproj b/HomeWork5-Solid/Question4/Question4.csproj new file mode 100644 index 0000000..6c1dc92 --- /dev/null +++ b/HomeWork5-Solid/Question4/Question4.csproj @@ -0,0 +1,10 @@ + + + + Exe + net10.0 + enable + enable + + +