1

I'm using ninject in my project and everything is going well. But I want use interception patter to log some requests in my web pages.

I've done some researches about it and I found one solution for asp.net MVC and I tried adapt to webforms but it's not working for me. What I've done was...

Create a PageBase which inherits from Ninject.Web.PageBase

     public partial class PageBase : Ninject.Web.PageBase
       {
           // some code
       }

Make all my pages inherits from my new PageBase

public partial class Default : PageBase
{
}

Create my interceptor

public class WebFormsInterceptor : SimpleInterceptor
    {
        readonly Stopwatch _stopwatch = new Stopwatch();

        protected override void BeforeInvoke(IInvocation invocation)
        {
            _stopwatch.Start();
        }

        protected override void AfterInvoke(IInvocation invocation)
        {
            _stopwatch.Stop();
            string message = string.Format("Execution of {0} took {1}.",
                invocation.Request.Method,
                _stopwatch.Elapsed);
            Log.Debug(message);
            _stopwatch.Reset();
        }
    }

And tried to configure kernel to intercept my PageBase... But here is the problem, because I don't know how can I configure it.

 kernel.Bind(x =>
                x.FromAssemblyContaining<myProject.PageBase>() 
                 //mistery configurations....
                 .Configure(b =>
                     b.Intercept()
                     .With<WebFormsInterceptor>()
                     ) //Intercept each method invocation 
            );

0 Answers0