extensión de intercepción ninject con WCF me da una “referencia a objeto no establecida como instancia de un objeto.” error

StackOverflow https://stackoverflow.com/questions/4297955

Pregunta

Estoy en trámites comenzó con la extensión de intercepción Ninject y no puede conseguir que funcione en mi servicio WCF. Con la extensión WCF, ninject funciona bien, es la intercepción que me está dando problemas. Tal vez estoy haciendo mal? Cuando trato de añadir el LinFuModel en el constructor del kernel que me dice que ya está cargado, así que supongo que eso es bueno.

Básicamente todo intercepción en los descansos de unión de mi servicio WCF, pero mi methodinterception simplemente funciona en el servicio (getData () está en el contrato de servicio).

editar: el siguiente tampoco funciona

  Kernel.Intercept((request) => request.Method.Name.StartsWith("Get"))
            .With<TimingInterceptor>(); 

extremo editar

protected override IKernel CreateKernel()
    {
        IKernel kernel = new StandardKernel(new ServiceModule());

        //var binding = kernel.Bind<MockBroker>().ToSelf();
        //binding.Intercept().With<TimingInterceptor>(); // THIS BREAKS

        kernel.InterceptAfter<Watch>(m => m.GetData(0), i => { i.ReturnValue = "BLABLABLA"; log.Info("INTERCEPTED!"); }); //WORKS

        //kernel.Bind<Watch>().ToSelf().Intercept().With(new TimingInterceptor()); //BREAKS
        //kernel.Bind<FileSystemBroker>().ToSelf().Intercept().With<TimingInterceptor>(); //BREAKS
        return kernel;
    }

public class TimingInterceptor : SimpleInterceptor
{
    readonly Stopwatch _stopwatch = new Stopwatch();
    //private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
    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.Info(message);
       _stopwatch.Reset();
    }
}

Gracias de antemano, Rinze

¿Fue útil?

Solución

Linfu compatible con el método sólo virtual intercepción. Cambiar todos los métodos interceptados a virtual o interruptor para DynamicProxy2.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top