我有一个通过 XML 文件配置的统一容器。配置完成后,我想通过代码为某些类型添加一些拦截。如何才能做到这一点?我有以下行为:
using System;
using System.Collections.Generic;
using System.Web.Mvc;
using Microsoft.Practices.Unity.InterceptionExtension;
using NLog;
namespace WebDibaelsaMVC.Utils.Behaviors
{
public class LoggingBehavior : IInterceptionBehavior
{
private readonly Logger _log = LogManager.GetLogger("Unity");
public IMethodReturn Invoke(IMethodInvocation input, GetNextInterceptionBehaviorDelegate getNext)
{
var msg = getNext()(input, getNext);
if (msg.Exception != null)
_log.ErrorException("Error d'unity.", msg.Exception);
return msg;
}
public IEnumerable<Type> GetRequiredInterfaces()
{
return new[] {typeof (IController)};
}
public bool WillExecute
{
get
{
return true;
}
}
}
}
我希望所有对通过容器解析的类型的 IController 方法的调用都通过这种行为。我该怎么做?