Skip to content

Added an example Singleton Implementation in C# #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31727.386
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SingletonPattern", "SingletonPattern\SingletonPattern.csproj", "{1D291EEF-B4FD-48F7-9587-6D58B646954E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{1D291EEF-B4FD-48F7-9587-6D58B646954E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{1D291EEF-B4FD-48F7-9587-6D58B646954E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{1D291EEF-B4FD-48F7-9587-6D58B646954E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{1D291EEF-B4FD-48F7-9587-6D58B646954E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A8359B11-3CCC-4FE9-B71D-42B6768AC973}
EndGlobalSection
EndGlobal
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace SingletonPattern
{
public class ExampleSingleton
{
private static ExampleSingleton exampleSingleton;

public string exampleText { get; set; }

private ExampleSingleton()
{
exampleText = "This is a example Text within the Singelton Instance.";
}

public static ExampleSingleton GetExampleSingeltonInstance()
{
if (exampleSingleton == null)
{
exampleSingleton = new ExampleSingleton();
}

return exampleSingleton;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;

namespace SingletonPattern
{
class Program
{
static void Main(string[] args)
{
//You get the global Instance of the exampleClass by Calling the Static GetExampleSingletonInstance Method declared in the Singleton class
var exampleSingleton = ExampleSingleton.GetExampleSingeltonInstance();
Console.WriteLine(exampleSingleton.exampleText);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
</PropertyGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"format": 1,
"restore": {
"C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingeltonPattern\\SingeltonPattern\\SingeltonPattern.csproj": {}
},
"projects": {
"C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingeltonPattern\\SingeltonPattern\\SingeltonPattern.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingeltonPattern\\SingeltonPattern\\SingeltonPattern.csproj",
"projectName": "SingeltonPattern",
"projectPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingeltonPattern\\SingeltonPattern\\SingeltonPattern.csproj",
"packagesPath": "C:\\Users\\andre\\.nuget\\packages\\",
"outputPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingeltonPattern\\SingeltonPattern\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\andre\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.NETCore.App.Host.win-x64",
"version": "[3.1.18, 3.1.18]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.100-rc.1.21463.6\\RuntimeIdentifierGraph.json"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\andre\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\andre\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"format": 1,
"restore": {
"C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj": {}
},
"projects": {
"C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj",
"projectName": "SingletonPattern",
"projectPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj",
"packagesPath": "C:\\Users\\andre\\.nuget\\packages\\",
"outputPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\andre\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.NETCore.App.Host.win-x64",
"version": "[3.1.18, 3.1.18]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.100-rc.1.21463.6\\RuntimeIdentifierGraph.json"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<RestoreSuccess Condition=" '$(RestoreSuccess)' == '' ">True</RestoreSuccess>
<RestoreTool Condition=" '$(RestoreTool)' == '' ">NuGet</RestoreTool>
<ProjectAssetsFile Condition=" '$(ProjectAssetsFile)' == '' ">$(MSBuildThisFileDirectory)project.assets.json</ProjectAssetsFile>
<NuGetPackageRoot Condition=" '$(NuGetPackageRoot)' == '' ">$(UserProfile)\.nuget\packages\</NuGetPackageRoot>
<NuGetPackageFolders Condition=" '$(NuGetPackageFolders)' == '' ">C:\Users\andre\.nuget\packages\;C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages</NuGetPackageFolders>
<NuGetProjectStyle Condition=" '$(NuGetProjectStyle)' == '' ">PackageReference</NuGetProjectStyle>
<NuGetToolVersion Condition=" '$(NuGetToolVersion)' == '' ">5.11.1</NuGetToolVersion>
</PropertyGroup>
<ItemGroup Condition=" '$(ExcludeRestorePackageImports)' != 'true' ">
<SourceRoot Include="C:\Users\andre\.nuget\packages\" />
<SourceRoot Include="C:\Program Files (x86)\Microsoft Visual Studio\Shared\NuGetPackages\" />
</ItemGroup>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<Project ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
{
"version": 3,
"targets": {
".NETCoreApp,Version=v3.1": {}
},
"libraries": {},
"projectFileDependencyGroups": {
".NETCoreApp,Version=v3.1": []
},
"packageFolders": {
"C:\\Users\\andre\\.nuget\\packages\\": {},
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages": {}
},
"project": {
"version": "1.0.0",
"restore": {
"projectUniqueName": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj",
"projectName": "SingletonPattern",
"projectPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj",
"packagesPath": "C:\\Users\\andre\\.nuget\\packages\\",
"outputPath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\obj\\",
"projectStyle": "PackageReference",
"fallbackFolders": [
"C:\\Program Files (x86)\\Microsoft Visual Studio\\Shared\\NuGetPackages"
],
"configFilePaths": [
"C:\\Users\\andre\\AppData\\Roaming\\NuGet\\NuGet.Config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.FallbackLocation.config",
"C:\\Program Files (x86)\\NuGet\\Config\\Microsoft.VisualStudio.Offline.config"
],
"originalTargetFrameworks": [
"netcoreapp3.1"
],
"sources": {
"C:\\Program Files (x86)\\Microsoft SDKs\\NuGetPackages\\": {},
"https://api.nuget.org/v3/index.json": {}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"projectReferences": {}
}
},
"warningProperties": {
"warnAsError": [
"NU1605"
]
}
},
"frameworks": {
"netcoreapp3.1": {
"targetAlias": "netcoreapp3.1",
"imports": [
"net461",
"net462",
"net47",
"net471",
"net472",
"net48"
],
"assetTargetFallback": true,
"warn": true,
"downloadDependencies": [
{
"name": "Microsoft.NETCore.App.Host.win-x64",
"version": "[3.1.18, 3.1.18]"
}
],
"frameworkReferences": {
"Microsoft.NETCore.App": {
"privateAssets": "all"
}
},
"runtimeIdentifierGraphPath": "C:\\Program Files\\dotnet\\sdk\\6.0.100-rc.1.21463.6\\RuntimeIdentifierGraph.json"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"version": 2,
"dgSpecHash": "LA5GKSdzUu5hWQ45SaQ8jz5WHYA/AR+dffOHfdKdmr6636tqHZt5AgUMqzYCtY9JnlGXacs/wj2xaknd3WEf9g==",
"success": true,
"projectFilePath": "C:\\Users\\andre\\Documents\\Repositories\\Hacktoberfest21\\Hacktoberfest2021\\Contributions\\SingletonPattern\\SingletonPattern\\SingletonPattern.csproj",
"expectedPackageFiles": [
"C:\\Users\\andre\\.nuget\\packages\\microsoft.netcore.app.host.win-x64\\3.1.18\\microsoft.netcore.app.host.win-x64.3.1.18.nupkg.sha512"
],
"logs": []
}