gpt4 book ai didi

c# - 统一拦截 : How to pass parameter into ICallHandler implementation?

转载 作者:行者123 更新时间:2023-11-30 17:17:12 26 4
gpt4 key购买 nike

我可以像这样将 message 参数传递给 ICallHandler 实现吗:

var logic = container.Resolve<IBussinessLogic>(message);

然后像这样使用它:

IMethodReturn ICallHandler.Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)
{
Console.WriteLine(
string.Format(
"Begin {0} with param {1}",
input.MethodBase.Name,
message // parameter I need to be passed
)
);

var result = getNext.Invoke()(input, getNext);

Console.WriteLine("End " + input.MethodBase.Name);
return result;
}

?

最佳答案

您传递给 Resolve 方法的 message 实际上是 Unity 要构造的命名实例名称。 Unity 使用此值来选择要使用的 IBusinessLogic 实现;在构建实现对象后,它会丢失。

因此,该值仅在对象构建期间存在于 Unity 中;您的 ICallHandler 无法以 you cannot intercept constructors 访问它.

关于c# - 统一拦截 : How to pass parameter into ICallHandler implementation?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6730498/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com