3

我可以像这样将消息参数传递给 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;
    }

?

4

2 回答 2

1

The message you're passing to the Resolve method is actually the named instance name for Unity to construct. This value is used by Unity to select which implementation of IBusinessLogic to use; after construction of the implementing object it is lost.

This value is therefore only within Unity during the object's construction; your ICallHandler cannot access it as you cannot intercept constructors.

于 2011-07-18T09:54:42.200 回答
1

看起来,史蒂夫威尔克斯是对的:“老实说,这听起来不可能使用拦截。”

http://unity.codeplex.com/discussions/265679

于 2011-08-09T08:39:53.853 回答