tags:

views:

31

answers:

1

How should I create application wide utility/manager classes that read settings from the database? Should I use static classes e.g.

public static class ThemeHelper
{
    private static string themeDirectory { get; private set; }

    static ThemeHelper()
    {
        // read from the database
        themeDirectory = "blue-theme";
    }

    public static string ResolveViewPath(string viewName)
    {
            string path = string.Format("~/themes/{0}/{1}.aspx", themeDirectory, viewName);
            // check if file exists...
            // if not, use default
            return path;
    }
}

or a static instance of a normal class, which is stored in the HttpApplicationState for example? Or should I use dependency injection library (like Ninject)?

A: 

Static classes and methods are okay for this kind of scenario. Pay attention however to static variables - their value will be shared between all clients of the same web application.

If you wish to cache the result but distinguish between clients (sessions), you can drop it to the Session collection.

Developer Art