How to access my variables in a web method?

后端 未结 2 906
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 13:48

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 v

相关标签:
2条回答
  • 2021-01-27 14:10

    somwhere in your application is a singleton of Ninject. reference this singleton within the webmethod. a similar process is being do in Ninject.Web.PageBase.

    0 讨论(0)
  • 2021-01-27 14:19

    You can directly retrieve it from the kernel using the IKernel.Get<T>() method:

    [WebMethod]
    public static string DoSomething()
    {
        NinjectModule module = new YourModule();
        IKernel kernel = new StandardKernel(module);
        var controller = kernel.Get<ISecurityController>();
        controller.WriteToLog();
    }
    
    0 讨论(0)
提交回复
热议问题