Ninject インターセプト拡張機能を使い始めましたが、WCF サービスで機能させることができません。WCF 拡張機能を使用すると、ninject は正常に動作します。問題を引き起こしているのはインターセプトです。多分私はそれを間違っていますか?LinFuModel をカーネル コンストラクターに追加しようとすると、既に読み込まれていることが示されるので、これで問題ないと思います。
基本的に、バインディングのすべての傍受は私の wcf サービスを壊しますが、私のメソッド傍受はサービスでのみ機能します (getData() はサービス コントラクトにあります)。
編集:以下も機能しません:
Kernel.Intercept((request) => request.Method.Name.StartsWith("Get"))
.With<TimingInterceptor>();
編集を終了
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();
}
}
よろしくお願いします、リンゼ