Ninject estensione intercettazione con WCF mi dà un “riferimento oggetto non impostato a un'istanza di un oggetto.” Errore

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

Domanda

Sto per iniziare con l'estensione intercettazione Ninject e non può ottenere al lavoro nel mio servizio WCF. Con l'estensione WCF, Ninject funziona bene, è l'intercettazione che è avermi dato problemi. Forse sto facendo male? Quando provo ad aggiungere il LinFuModel nel costruttore kernel mi dice che è già caricato, quindi credo che di buono.

In pratica tutto l'intercettazione sulle rotture di legame il mio servizio WCF, ma la mia methodinterception funziona solo sul servizio (getData () è nel contratto di servizio).

modifica: le seguenti, inoltre, non opera :

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

fine modifica

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();
    }
}

Grazie in anticipo, Rinze

È stato utile?

Soluzione

Linfu supporta il metodo di intercettazione solo virtuale. Modificare tutti i metodi intercettati a virtuale o passare a DynamicProxy2.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top