C # Utility Functionality Static Method / Static Class / Singleton Template

I create a utility method GetServiceTicketNumber()inside the utility class, since the method will be used often, I do not want to instantiate each time, so I made the method and _ticket as static.

UtilityManager also contains several other methods.

My question is:

1) Is this implemented correctly?

2) whether it is necessary to make UtilityManageralso a static class / not ?, what difference?

3) Is the code below (for the TicketProvider function) written in a singleton template? (Given that most of the singleton class creates an instance of the same class UtilityManager.)

other information: a class called in an Asp.Net application

public  sealed class UtilityManager
{    
    public static readonly TicketProvider _ticket = new TicketProvider();

    public static int GetServiceTicketNumber()
    {       
        return _ticket.GetTicket();
    }
}
+3
source
2

, , stylecop, , . TicketProvider, , , . , , , . :

public static class UtilityManager
{  
    static UtilityManager()
    {
        Ticket = new TicketProvider();
    }

    public static TicketProvider Ticket { get; private set; }

    public static int GetServiceTicketNumber()
    {       
        return Ticket.GetTicket();
    }
}
+3

1: ; ; , , AppDomain. , , . .

2: ( ); , , ,

3: . , , , .

, , - , IoC/DI (, , ). , .

, - ( ). ( ) ( ).

+4

All Articles