.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Question About singleton class

Posted By:      Posted Date: October 25, 2010    Points: 0   Category :ASP.Net

Just wanted to know if a singleton class could be inherited and derived.


View Complete Post

More Related Resource Links

Singleton Pattern and Abstract Class


I know what Singleton Pattern means and Abstract class means.

What I wanted to know was how would this apply to real world.

Could anyone give me any good example or simple explanation.

Say I have a simple website, why would I use any of the above if any.

Why would it simplify my architechture.

Thanks in advace. 

singleton class and multithreading


I have a singleton class thats used throughout an application.  The app will be multi threaded, each thread will access methods in the singleton class.  Is it best to create an instance of the singleton class at application startup then pass that into each thread, or is it safe to create an instance in each thread separately ?  (I check that no instance currently exists in the singleton class itself, so only 1 instance will ever be invoked)

UserControl Resouces Singleton Instance Question


Given, a viewmodel referred to in a UserControl reource like this:

 <local:MainVM x:Key="VM"></local:MainVM>

Everything works great with respect to finding resources etc.

Now the usercontrol has bindings like this:

      DataContext="{Binding Sour

Question on a class that is reused


I have a generic class that just has the following:

    public class GenericMap

        private int _Number_1 = 0,
                    _Number_2 = 0,
                    _Number_3 = 0,
                    _Number_4 = 0,
                    _Number_5 = 0,
                    _Number_6 = 0,
                    _Number_7 = 0,
                    _Number_8 = 0;
        private string _String_1 = string.Empty,

Design Question - Child Class Reference


There has to be a better way to design the following:

public class Member {
  public int stateID {get; set;}

  public State state {
    get {
      if (this.stateID > 0) 
        state = State.GetByID(this.stateID);

public class State {
  public string name {get; set; }

  public static State GetByID(int id) {
    //populates state from db

Now if I loop through a list of members and need to display the state name for each member and I call "myMember.State.name" - I'll get the name of the state but it costs me an extra query everytime I call that - even though some of the states may be the same.

Is there a way somehow keep some sort of cache of state name from the db for access?


CLASS question


Hi guys!


I have a class like this:


namespace Core.Utils
    public class getText

        public string getText(string ext){

            string result = "The String: " + ext
            return result;



Normally, I use it like this:


var xx = new getText();

var yy = xx.getText("AAA");



I want to know how to be able to use it like this:


var yy = new getText("AAA");


It's that possible?

Thanks in advance!


Binding Question How does one set datacontext to same class in XAML?


I have a usercontrol with one button in it.  I want to set the text via a property getter setter using the INotifyPropertyChanged interface in code behind.  I can get it to work if I set the DATACONTEXT in code behind in the CTOR like this : DataContext = this;  Everything works perfect. 

But here's the problem.  If I try to do this in xaml by defining an XMLNS which points to the folder this usercontrol is in, and then attempt to reference it as a resouce like this <local:XXXXXX  <-------The XXXX which is the class name of this control can't be found?  Is that wierd?  Can't a resource be itself?  So that I can set the Datacontext in the XAML instead of code behind?  I've tried to bind to relative source self, but cannot set the property (Event when I attempted to created a dependency property).....  Just wondering how one sets up Datacontext to the same class? 


Class Design Question



I have a question about class design. Currently I am working with following tables:

| Forms
| FormID (PK)
| CommitmentID (FK)
| ...

| Commitments
| CommitmentID (PK)
| CommitDesc
| ...

| Pricings
| PricingID (PK)
| Desc
| CommitmentID (FK)
| ...

| PricingTiers
| TierID (PK)
| PricingID (FK)
| Desc
| ...

Forms <-one to one-> Commitment
Commitment <-one to many-> Pricing
Pricing <-one to many-> PricingTiers

When designing the classes what would be considered a best practice ... for instance at the moment I have 4 classes "Form", "Commitment", "Pricing", and "PricingTier" respectively.

Form class has a public property Commitment which represents an instance of the Commitment class.

Commitment class has a public property List<Pricing> which represents the one to many (Commitment - Pricing) relat

Data Class Best Practices Question


Hi all.

I have a class called employee.  I have several private fields (i.e. mHiredDate, mSickDays, mVacationDays, etc.).  I instantiate employee objects thru out my website application.  When I make a change to the private fields using the public property set method, is it a better practice to make the changes thru out the session and save the values back to the database near the end of the session or make the set make the change to the database everytime it is called?  Does the same go for get ?  Do I have my get goto the database and grab the value everytime I need it ?

I hope my question is clear enough. 

Thanks Smile


Question on WorkflowApplication class design ( Func Properties)





I found out that the Workflow Application class offers Func<T> properties to inject code for example when a error occurs.

whats the reason behind the Design Decission of giving the WorkFlow Foundation class Func<T> properties instead of event?


For Example


 Func<WorkflowApplicationUnhandledExceptionEventArgs, UnhandledExceptionAction> OnUnhandledException { get

; set

; }





 Action<WorkflowApplicationCompletedEventArgs> Completed { get

; set

; }


Is it just to prevent the multiple receipients ?

Or is it related to memory mangement due to fix pins caused by eventhandlers ? To be honest i must confess that i'm not sure wether Func<T> will created a fix pin in memory :-(

I'm not sure about if this is good or not, but it would be very nice to get knowledge of the reason why this class is event

debug and class diagram question, visual studio 2008


Hi. Im working on a project where there are a lot of imported dll's from a company that have e-soultions. now some times when i debug i get to a dead end when a class or method is used from their project. They supplied me with their sourcecode so i got that, now the question is can i somehow debug in my main project and to trace it to their project if i got the source code? (hope im clear on what i want to do)


second question is that i want to print all the classes and inherits, can i get that somehow with the different relations between classes straigh out of visual studio? i know about class diagram but it dont show relations.


thanks for reply

Singleton Design Pattern in C#, Vb.NET

Ensure a class has only one instance and provide a global point of access to it.

Class Diagrams

Class diagrams show the static structure of the systems. Classes define the properties of the objects which belong to them. These include:

Attributes - (second container) the data properties of the classes including type, default value and constraints.

Creating a Simple Class in C#

The second article in the C# Object-Oriented Programming tutorial describes how classes are created in C# and how behaviour, in the form of publicly visible and private, hidden methods can be added. This demonstrates some of the uses of encapsulation

Static Class for Beginners

In general, the members of a class can be accessed by instance of that class when they are in public, but there comes a situation to access or call members of a class without an instance and this can be achieved by declaring them as static

Singleton Design Pattern in Asp.net using C#

When we want to make a only one instance of a class and also making sure that there is a global access point to that object then the design pattern we user is called Singleton. The pattern ensures that the class is instantiated only once and that all requests are directed to that one and only object.
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend