WCFを使用したNinject傍受拡張は、「オブジェクトのインスタンスに設定されていないオブジェクト参照」を提供します。エラー
-
28-09-2019 - |
質問
Ninject Interception Extensionを始めていますが、WCFサービスで動作させることはできません。 WCF拡張機能により、Ninjectは正常に機能します。これは、私にトラブルを与えている傍受です。多分私はそれを間違っていますか?カーネルコンストラクターにlinfumodelを追加しようとすると、すでにロードされていることがわかりますので、それは良いことだと思います。
基本的に、バインディングのすべての傍受は私のWCFサービスを破壊しますが、私のMethodInterceptionはサービスで機能するだけです(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();
}
}
事前にありがとう、リンゼ
解決
LINFUは、仮想メソッドインターセプトのみをサポートしています。すべての傍受されたメソッドを仮想に変更するか、DynamicProxy2に切り替えます。
所属していません StackOverflow