這是我第一次使用流利註冊的攔截器,並且我錯過了一些東西。通過以下注冊,我可以解析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