I am using ASP.NET Webforms and in one page I want to make an AJAX call to a web method in the code behind. The problem is that web methods are static and I can't access page variables. I need to be able to have Ninject inject a dependency. Is there a way to do this in a web method?
public partial class Default : Ninject.Web.PageBase
{
[Inject]
public ISecurityController SecurityController { get; set; }
[WebMethod]
public static string DoSomething()
{
SecurityController.WriteToLog(); // Can't access SecurityController because it doesn't exist.
}
}
Since web methods are static it almost seems silly to even have it in the code behind for the page because it can't actually interact with the page. It's an isolated island in the code behind. Is there a better way to accomplish this? Or at the very least is there a way I can have Ninject inject ISecurityController into the web method somehow?