-
Notifications
You must be signed in to change notification settings - Fork 4
Interceptors
hendryluk edited this page Feb 11, 2015
·
2 revisions
Reference:https://docs.jboss.org/weld/reference/1.0.0/en-US/html/interceptors.html
[Logged]
public class LoggingInterceptor: IAroundInvokeInterceptor
{
[Inject] ILogger _logger;
public virtual Task<object> AroundInvoke(IInvocationContext context)
{
try
{
_logger.Debug("Enter {0}", context.Method);
return await context.Proceed();
}
finally
{
_logger.Debug("Exit {0}", context.Method);
}
}
}
,,,
[Logged] is an interceptor-binding that you declare as the following:
```csharp
public LoggedAttribute: InterceptorBindingAttribute { }
To apply this interceptor, mark your class or methods with the interceptor-binding.
[Logged]
public class Foo
{
/* all methods will be intercepted */
}
public class Bar
{
[Logged]
public virtual void DoSomething()
{
/* only this method will be intercepted */
}
}