这是我第一次使用流利注册的拦截器,并且我错过了一些东西。通过以下注册,我可以解析IProcessingStep,它是一个代理类,拦截器位于__interceptors数组中,但由于某种原因,拦截器未被调用。任何想法我失踪?代理被创建,并且拦截器在__interceptors数组中,但是拦截器从未被调用
感谢, 德鲁
AllTypes.Of<IProcessingStep>()
.FromAssembly(Assembly.GetExecutingAssembly())
.ConfigureFor<IProcessingStep>(c => c
.Unless(Component.ServiceAlreadyRegistered)
.LifeStyle.PerThread
.Interceptors(InterceptorReference.ForType<StepLoggingInterceptor>()).First
),
Component.For<StepMonitorInterceptor>(),
Component.For<StepLoggingInterceptor>(),
Component.For<StoreInThreadInterceptor>()
public abstract class BaseStepInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
IProcessingStep processingStep = (IProcessingStep)invocation.InvocationTarget;
Command cmd = (Command)invocation.Arguments[0];
OnIntercept(invocation, processingStep, cmd);
}
protected abstract void OnIntercept(IInvocation invocation, IProcessingStep processingStep, Command cmd);
}
public class StepLoggingInterceptor : BaseStepInterceptor
{
private readonly ILogger _logger;
public StepLoggingInterceptor(ILogger logger)
{
_logger = logger;
}
protected override void OnIntercept(IInvocation invocation, IProcessingStep processingStep, Command cmd)
{
_logger.TraceFormat("<{0}> for cmd:<{1}> - begin", processingStep.StepType, cmd.Id);
bool exceptionThrown = false;
try
{
invocation.Proceed();
}
catch
{
exceptionThrown = true;
throw;
}
finally
{
_logger.TraceFormat("<{0}> for cmd:<{1}> - end <{2}> times:<{3}>",
processingStep.StepType, cmd.Id,
!exceptionThrown && processingStep.CompletedSuccessfully
? "succeeded" : "failed",
cmd.CurrentMetric==null ? "{null}" : cmd.CurrentMetric.ToString());
}
}
}
看到http://stackoverflow.com/questions/1188957/castle-interceptors-with-fluent-interface – 2010-04-16 03:58:59
我看这一点,它似乎并不适用。我的拦截器正在实例化并附加到代理。另外,使用任何WithService事件都会导致服务未被注册。 – drewburlingame 2010-04-16 04:30:00