こんにちは、ユニティ インターセプトを使用しようとしています (ユニティ コンテナーは使用したくありません)。ランタイムを構成できますが、構成から構成する方法がわかりません。
私のコード:
public interface ICalculator
{
int Add(int first, int second);
int Multiply(int first, int second);
}
行動:
internal class LogBehavior : IInterceptionBehavior
{
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
// My Code
IMethodReturn result = getNext()(input, getNext);
return result;
}
public IEnumerable<Type> GetRequiredInterfaces()
{
return Type.EmptyTypes;
}
public bool WillExecute {
get { return true; }
}
}
そして、これが私がそれを呼んでいる方法です
public static void Main(string[] args)
{
var calculator = new Calculator();
var calculatorProxy = Intercept.ThroughProxy<ICalculator>(calculator,
new InterfaceInterceptor(), new[] { new LogBehavior() });
Console.WriteLine(calculatorProxy.Add(2, 2));
Console.ReadKey();
}
これは機能しています。これを構成ファイルから構成する必要があります。助けてください