public class SharedCacheData : ISharedCacheData
{
private readonly ISharedPetsService mPetsService;
private static ISharedEmployeeService mSharedEmployeeService;
public SharedCacheData(ISharedPetsService petsService, ISharedEmployeeService employeeService)
{
mPetsService = petsService;
mSharedEmployeeService = employeeService;
}
public static string GetUserFullName(string key)
{
Hashtable value = HttpContext.Current.Application[USERFULLNAME_KEY] as Hashtable;
if (value == null)
{
value = new Hashtable();
HttpContext.Current.Application[USERFULLNAME_KEY] = value;
}
if (value.ContainsKey(key))
return value[key] as string;
string name = mSharedEmployeeService.FindOneUser(key);
value[key] = name;
return name;
}
Whether initialize static field mSharedEmployeeService (service) in constructors?
No, that’s generally a bad idea. Every time you create a new instance, it will be replacing the static variable. That’s almost certainly not what you want to do.
I wonder whether actually there should be two classes here – one for the pets service and one for the employee service. It’s hard to tell from the code presented, but what we’ve got here really doesn’t look like a good idea.