Ninject extension interception avec WCF me donne une « référence d'objet non définie à une instance d'un objet. » Erreur

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

Question

Je suis en train a commencé avec l'extension d'interception Ninject et ne peut pas le faire au travail dans mon service WCF. Avec l'extension de WCF, ninject fonctionne très bien, il est l'interception qui me donne du mal. Peut-être que je fais mal? Lorsque je tente d'ajouter le LinFuModel dans le constructeur du noyau, il me dit qu'il est déjà chargé, donc je suppose que ce bien.

En fait toute interception sur les pauses liant mon service WCF, mais mon methodinterception travaille uniquement sur le service (getData () est dans le contrat de service).

modifier: ce qui suit ne fonctionne pas non plus :

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

modifier final

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

Thanx à l'avance, Rinze

Était-ce utile?

La solution

Linfu ne supporte que l'interception des méthodes virtuelles. Changer toutes les méthodes interceptées au virtuel ou passer à DynamicProxy2.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top