From 1921b5f60340814bb83760501ff83476cd6a370a Mon Sep 17 00:00:00 2001 From: syneffort Date: Fri, 22 Jul 2022 10:44:01 +0900 Subject: [PATCH] Singleton --- DesignPattern/DesignPattern.sln | 25 ++++++++ DesignPattern/DesignPattern/App.config | 6 ++ .../DesignPattern/DesignPattern.csproj | 53 +++++++++++++++++ DesignPattern/DesignPattern/Program.cs | 15 +++++ .../DesignPattern/Properties/AssemblyInfo.cs | 36 +++++++++++ DesignPattern/Singleton/App.config | 6 ++ DesignPattern/Singleton/Client.cs | 20 +++++++ DesignPattern/Singleton/Configuration.cs | 35 +++++++++++ DesignPattern/Singleton/Program.cs | 18 ++++++ .../Singleton/Properties/AssemblyInfo.cs | 36 +++++++++++ DesignPattern/Singleton/Singleton.csproj | 59 +++++++++++++++++++ DesignPattern/Singleton/packages.config | 4 ++ 12 files changed, 313 insertions(+) create mode 100644 DesignPattern/DesignPattern.sln create mode 100644 DesignPattern/DesignPattern/App.config create mode 100644 DesignPattern/DesignPattern/DesignPattern.csproj create mode 100644 DesignPattern/DesignPattern/Program.cs create mode 100644 DesignPattern/DesignPattern/Properties/AssemblyInfo.cs create mode 100644 DesignPattern/Singleton/App.config create mode 100644 DesignPattern/Singleton/Client.cs create mode 100644 DesignPattern/Singleton/Configuration.cs create mode 100644 DesignPattern/Singleton/Program.cs create mode 100644 DesignPattern/Singleton/Properties/AssemblyInfo.cs create mode 100644 DesignPattern/Singleton/Singleton.csproj create mode 100644 DesignPattern/Singleton/packages.config diff --git a/DesignPattern/DesignPattern.sln b/DesignPattern/DesignPattern.sln new file mode 100644 index 0000000..8c8f448 --- /dev/null +++ b/DesignPattern/DesignPattern.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.32630.194 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Singleton", "Singleton\Singleton.csproj", "{37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {F3BACC7E-F135-42F5-B308-757DA855C6F6} + EndGlobalSection +EndGlobal diff --git a/DesignPattern/DesignPattern/App.config b/DesignPattern/DesignPattern/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/DesignPattern/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/DesignPattern/DesignPattern.csproj b/DesignPattern/DesignPattern/DesignPattern.csproj new file mode 100644 index 0000000..eeffd3f --- /dev/null +++ b/DesignPattern/DesignPattern/DesignPattern.csproj @@ -0,0 +1,53 @@ + + + + + Debug + AnyCPU + {0AFC8AB1-896C-4686-A5EA-58DE7A3CB612} + Exe + DesignPattern + DesignPattern + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DesignPattern/DesignPattern/Program.cs b/DesignPattern/DesignPattern/Program.cs new file mode 100644 index 0000000..0c6fd1a --- /dev/null +++ b/DesignPattern/DesignPattern/Program.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DesignPattern +{ + class Program + { + static void Main(string[] args) + { + } + } +} diff --git a/DesignPattern/DesignPattern/Properties/AssemblyInfo.cs b/DesignPattern/DesignPattern/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..0ffce32 --- /dev/null +++ b/DesignPattern/DesignPattern/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("DesignPattern")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("DesignPattern")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("0afc8ab1-896c-4686-a5ea-58de7a3cb612")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Singleton/App.config b/DesignPattern/Singleton/App.config new file mode 100644 index 0000000..193aecc --- /dev/null +++ b/DesignPattern/Singleton/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/DesignPattern/Singleton/Client.cs b/DesignPattern/Singleton/Client.cs new file mode 100644 index 0000000..3bdc905 --- /dev/null +++ b/DesignPattern/Singleton/Client.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Singleton +{ + class Client + { + public static void HowToTest() + { + var username = Configuration.Settings["username"]; + var server = Configuration.Settings["server"]; + + Console.WriteLine($"server: {server}"); + Console.WriteLine($"username: {username}"); + } + } +} diff --git a/DesignPattern/Singleton/Configuration.cs b/DesignPattern/Singleton/Configuration.cs new file mode 100644 index 0000000..cf741f9 --- /dev/null +++ b/DesignPattern/Singleton/Configuration.cs @@ -0,0 +1,35 @@ +using Newtonsoft.Json.Linq; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Singleton +{ + public sealed class Configuration + { + public static Configuration Settings { get; } = new Configuration(); + + private Dictionary dict = new Dictionary(); + + private Configuration() + { + LoadConfig(); + } + + private void LoadConfig() + { + string str = File.ReadAllText("config.json"); + JObject jo = JObject.Parse(str); + + foreach (KeyValuePair kv in jo) + { + dict.Add(kv.Key, kv.Value); + } + } + + public object this[string key] { get { return dict[key]; } } + } +} diff --git a/DesignPattern/Singleton/Program.cs b/DesignPattern/Singleton/Program.cs new file mode 100644 index 0000000..20fdd43 --- /dev/null +++ b/DesignPattern/Singleton/Program.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Singleton +{ + class Program + { + static void Main(string[] args) + { + Client.HowToTest(); + + Console.ReadKey(); + } + } +} diff --git a/DesignPattern/Singleton/Properties/AssemblyInfo.cs b/DesignPattern/Singleton/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..847e302 --- /dev/null +++ b/DesignPattern/Singleton/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// 어셈블리에 대한 일반 정보는 다음 특성 집합을 통해 +// 제어됩니다. 어셈블리와 관련된 정보를 수정하려면 +// 이러한 특성 값을 변경하세요. +[assembly: AssemblyTitle("Singleton")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("Singleton")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// ComVisible을 false로 설정하면 이 어셈블리의 형식이 COM 구성 요소에 +// 표시되지 않습니다. COM에서 이 어셈블리의 형식에 액세스하려면 +// 해당 형식에 대해 ComVisible 특성을 true로 설정하세요. +[assembly: ComVisible(false)] + +// 이 프로젝트가 COM에 노출되는 경우 다음 GUID는 typelib의 ID를 나타냅니다. +[assembly: Guid("37fe4d0c-a213-4ea5-b3ef-db2db3971ace")] + +// 어셈블리의 버전 정보는 다음 네 가지 값으로 구성됩니다. +// +// 주 버전 +// 부 버전 +// 빌드 번호 +// 수정 버전 +// +// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를 +// 기본값으로 할 수 있습니다. +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/DesignPattern/Singleton/Singleton.csproj b/DesignPattern/Singleton/Singleton.csproj new file mode 100644 index 0000000..8a68e5a --- /dev/null +++ b/DesignPattern/Singleton/Singleton.csproj @@ -0,0 +1,59 @@ + + + + + Debug + AnyCPU + {37FE4D0C-A213-4EA5-B3EF-DB2DB3971ACE} + Exe + Singleton + Singleton + v4.8 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/DesignPattern/Singleton/packages.config b/DesignPattern/Singleton/packages.config new file mode 100644 index 0000000..bc2a97e --- /dev/null +++ b/DesignPattern/Singleton/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file