1

我正在尝试使用统一拦截来拦截异常。我定义了一个接口和一个实现该接口的类。

我正在尝试使用 InterfaceInterception,但 Unity 抛出了一个类型不可拦截的异常。我检查了我的类,与成功拦截的其他类的唯一区别是这个类和接口声明了一些事件。如果我使用 VirtualMethodInterception,Unity 不会抛出异常。

我正在使用 C#

为什么 VirtualMethodInterceptor 工作,为什么 InterfaceInterceptor 不工作?

以下是实际代码的简化。

public interface IInterfaceToBeInterceptable : IDisposable
{
    event EventHandler<ItemSavedEventArgs> ItemSaved;

    event EventHandler<GenericEventArgs<bool>> JobWasCompleted;

    InvocationResult InvokeJob( JobInvocationParams invocationParams );
}

public class ClassToBeInterceptable : IInterfaceToBeInterceptable
{
    public event EventHandler<ItemSavedEventArgs> ItemSaved;

    public event EventHandler<GenericEventArgs<bool>> JobWasCompleted;

    public InvocationResult InvokeJob( JobInvocationParams invocationParams )
    {
        // Implementation
    }

    public void Dispose()
    {
        // Implementation
    }

    private static GetInfo()

    {
        // Implementation
    }
}

统一配置是

<register type="IInterfaceToBeInterceptable" mapTo="ClassToBeInterceptable">
     <lifetime type="singleton" />

     <interceptor type="InterfaceInterceptor" />
     <interceptionBehavior type="Exceptionbehavior"  />
     <interceptionBehavior type="LoggingBehaviour" />
  </register>

异常详情如下

例外是:ArgumentException - ClassToBeInterceptable 类型不可拦截。参数名称:interceptedType

编辑 :-

该类被指定为另一个类的依赖项,并且在构建另一个依赖于“另一个”类(或者更准确地说,“另一个”类的接口)的类的过程中抛出了上述异常。

4

0 回答 0