I have a static class and I need to inject some instances into it. A static class can have a static constructor but it must be parameterless. So, how am I supposed to inject something into it?
I do not wish to create a singleton. I wish to have a static class, and one of its methods operate on an instance that should be injected. Below is an example of the sort of thing I need:
public static class AuthenticationHelper
{
// Fields.
private static object _lock = new object();
private static readonly UserBusiness _userBusiness; // <-- this field needs to be injected.
// Public properties.
public static User CurrentUser
{
get
{
if (IsAuthenticated)
{
User user = (User)Context.Session[SessionKeys.CURRENT_USER];
if (user == null)
{
lock (_lock)
{
if (user == null)
{
user = _userBusiness.Find(CurrentUserId);
Context.Session[SessionKeys.CURRENT_USER] = user;
}
}
}
return user;
}
return null;
}
}
public static int CurrentUserId { get; /* implementation omitted for brevity */ }
public static bool IsAuthenticated { get; /* implementation omitted for brevity */ }
}
Background info: this is an MVC4 application, so I'm using ninject.mvc3 plugin.
PS.: I've seen some questions concerning Ninject and static methods, but none of them seemed to address an issue like this.