/src/LinFu.AOP.Interfaces/FieldInterceptorRegistry.cs
http://github.com/philiplaureano/LinFu · C# · 45 lines · 25 code · 3 blank · 17 comment · 3 complexity · 4aea687bfdac3ef41231bba13b59cb35 MD5 · raw file
- namespace LinFu.AOP.Interfaces
- {
- /// <summary>
- /// Represents a registry class that allows users to intercept fields from a single location.
- /// </summary>
- public class FieldInterceptorRegistry
- {
- private static readonly object _lock = new object();
- private static IFieldInterceptor _interceptor;
- private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
- /// <summary>
- /// Gets current the <see cref="IFieldInterceptionContext" /> associated with the
- /// <see cref="FieldInterceptorRegistry" />.
- /// </summary>
- /// <param name="context">
- /// The <see cref="IFieldInterceptionContext" /> instance that describes the state of the method call
- /// when the field getter or setter is called.
- /// </param>
- /// <returns>The field interceptor that will be used to preempt field getter and setter calls.</returns>
- public static IFieldInterceptor GetInterceptor(IFieldInterceptionContext context)
- {
- lock (_lock)
- {
- if (_interceptor != null && _interceptor.CanIntercept(context))
- return _interceptor;
- }
- return null;
- }
- /// <summary>
- /// Sets current the <see cref="IFieldInterceptionContext" /> that will be associated with the
- /// <see cref="FieldInterceptorRegistry" />.
- /// </summary>
- /// <param name="interceptor">The field interceptor that will be used to preempt field getter and setter calls.</param>
- public static void SetInterceptor(IFieldInterceptor interceptor)
- {
- lock (_lock)
- {
- _interceptor = interceptor;
- }
- }
- }
- }