/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

  1. namespace LinFu.AOP.Interfaces
  2. {
  3. /// <summary>
  4. /// Represents a registry class that allows users to intercept fields from a single location.
  5. /// </summary>
  6. public class FieldInterceptorRegistry
  7. {
  8. private static readonly object _lock = new object();
  9. private static IFieldInterceptor _interceptor;
  10. private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
  11. /// <summary>
  12. /// Gets current the <see cref="IFieldInterceptionContext" /> associated with the
  13. /// <see cref="FieldInterceptorRegistry" />.
  14. /// </summary>
  15. /// <param name="context">
  16. /// The <see cref="IFieldInterceptionContext" /> instance that describes the state of the method call
  17. /// when the field getter or setter is called.
  18. /// </param>
  19. /// <returns>The field interceptor that will be used to preempt field getter and setter calls.</returns>
  20. public static IFieldInterceptor GetInterceptor(IFieldInterceptionContext context)
  21. {
  22. lock (_lock)
  23. {
  24. if (_interceptor != null && _interceptor.CanIntercept(context))
  25. return _interceptor;
  26. }
  27. return null;
  28. }
  29. /// <summary>
  30. /// Sets current the <see cref="IFieldInterceptionContext" /> that will be associated with the
  31. /// <see cref="FieldInterceptorRegistry" />.
  32. /// </summary>
  33. /// <param name="interceptor">The field interceptor that will be used to preempt field getter and setter calls.</param>
  34. public static void SetInterceptor(IFieldInterceptor interceptor)
  35. {
  36. lock (_lock)
  37. {
  38. _interceptor = interceptor;
  39. }
  40. }
  41. }
  42. }