Je commence avec l'extension d'interception Ninject et je n'arrive pas à l'utiliser dans mon service WCF. Avec l'extension WCF, ninject fonctionne bien, c'est l'interception qui me pose problème. Peut-être que je me trompe? Lorsque j'essaie d'ajouter le LinFuModel dans le constructeur du noyau, il me dit qu'il est déjà chargé, donc je suppose que c'est bon. Fondamentalement toute interception sur la liaison rompt mon service wcf, mais ma méthodeinterception fonctionne seulement sur le service (getData() est dans le contrat de service).L'extension d'interception Ninject avec WCF me donne une "Référence d'objet non définie sur une instance d'un objet". erreur
modifier: ce qui suit ne fonctionne pas aussi:
Kernel.Intercept((request) => request.Method.Name.StartsWith("Get"))
.With<TimingInterceptor>();
modifier fin
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
Je l'ai essayé avec un attribut sur ma classe MockBroker, et cela fonctionne. Encore ne peut pas l'obtenir pour travailler sur la liaison si. En outre, il semble que les méthodes doivent non seulement être virtuelles, mais aussi publiques? – Syg