ttmind

Main Navigation

ttmind
  • jim-jams
  • Tech
  • Positive
Login

Login

Facebook Google

OR

Remember me Forgot password?

Don't have account? Signup here.

Sort by Categorys

.Net

PHP

Java

JavaScript

Database

Server

Client Side

Tools

Artificial Intelligence

Cloud

Hybrid Development

Event

Smart City

Education

Security

Scrum

Digital Marketing

APP Development

Business

Internet

Simulation

Art

Network

Microservices

Architecture

Technology

Leadership

    Top Articles

  • How Does Social Media Bring People Together?
    TTMind Author
  • How to read appSettings JSON from Class Library in ASP.NET Core
    Anil Shrestha
  • Printing Support In Asp.Net Core
    TTMind Author
  • HOW TO EXTRACT TEXT FROM IMAGE USING JAVASCRIPT (OCR with Tesseract.js)?
    Prakash Pokhrel
  • Images Upload REST API using ASP.NET Core
    Prakash Pokhrel
  • Related Topic

  • How to read appSettings JSON from Class Library in ASP.NET Core
  • Printing Support In Asp.Net Core
  • Images Upload REST API using ASP.NET Core
  • How to use IActionFilter, IAsyncActionFilter in ASP.NET Core MVC?
  • ASP.NET CORE - Blazor CRUD operation using ADO.NET
  • Tech
  • About Us
  • Contact Us
  • TechHelp
  • PositiveHelp
  • Jim-Jams Help
  • Terms & Conditions

© Copyright ttmind.com

Main Content

Singleton Design Pattern in C#

.Net C# about 7 years ago || 11/13/2018 || 4.1 K View

  • Hide

What is Singleton Design Pattern?

Singleton Design Pattern is one of the design pattern among the four design patterns which falls under the creational design pattern. It makes sure that at a given time only one instance of a class is created which helps in the global access of the single point of instance.

why to use Singleton Pattern??

  • IT supports lazy loading
  • Sharing common data among applications
  • Easy to maintain the single point of access to a particular instance
  • Reduce overhead of initializing new objects again and again
  • Reusability of the objects
  • Suitable for Facades and Service Proxies
  • It can be used for Caching

Disadvantages??

IT does not support Multithreaded access and the object needs to be serialized with locking procedure.

How to implement Singleton Design Pattern??

To implement Singleton pattern we must initializes the constructor of the type as private and all the other methods needs to be defined public to be accessed by the outer applications.

An implementation is provided below:

public class Singleton
{
   private static Singleton instance;

   private Singleton() {}

   public static Singleton Instance
   {
       get{
         if(instance == null){
            instance = new Singleton();
         }
         return instance;
       }
   }
}

The above implementation also provides lazy initialization.

When the Instance property is accessed from outside the Singleton instance is initialized .

Also visit the link below: Click Here

  • 2
  • 0
  • 0
    • Facebook
    • Twitter
    • Google +
    • LinkedIn

About author

Binod  Bhandari

Binod Bhandari

Life is not just about thrieving but all about living.

Reset Your Password
Enter your email address that you used to register. We'll send you an email with your username and a link to reset your password.

Quick Survey