我应该如何创建从数据库读取设置的应用程序范围的实用程序/管理器类?我应该使用静态类吗?
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;
}
}或者是一个普通类的静态实例,例如存储在HttpApplicationState中?或者我是否应该使用依赖注入库(如Ninject)?
发布于 2010-03-09 01:09:41
静态类和方法适用于这种场景。但是,要注意静态变量--它们的值将在同一个web应用程序的所有客户端之间共享。
如果您希望缓存结果,但要区分客户端(会话),则可以将其放到会话集合中。
https://stackoverflow.com/questions/2403090
复制相似问题