/src/LinFu.AOP.Interfaces/MethodBodyReplacementProviderRegistry.cs

http://github.com/philiplaureano/LinFu · C# · 44 lines · 22 code · 3 blank · 19 comment · 2 complexity · ab9786f938d55bda78110f98b9979588 MD5 · raw file

  1. namespace LinFu.AOP.Interfaces
  2. {
  3. /// <summary>
  4. /// Represents a static type that allows users to register a method replacement provider from a single location.
  5. /// </summary>
  6. public static class MethodBodyReplacementProviderRegistry
  7. {
  8. private static readonly object _lock = new object();
  9. private static IMethodReplacementProvider _provider;
  10. private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
  11. /// <summary>
  12. /// Returns the provider that is currently attached to the registry.
  13. /// </summary>
  14. /// <param name="host">The type that is currently being intercepted.</param>
  15. /// <param name="info">The <see cref="IInvocationInfo" /> object that describes the invocation context.</param>
  16. /// <returns>
  17. /// A <see cref="IMethodReplacementProvider" /> that will determine the code that will be executed once a target
  18. /// method is called.
  19. /// </returns>
  20. public static IMethodReplacementProvider GetProvider(object host, IInvocationInfo info)
  21. {
  22. if (_provider == null)
  23. return null;
  24. return _provider.CanReplace(host, info) ? _provider : null;
  25. }
  26. /// <summary>
  27. /// Assigns the <paramref name="provider" /> to the MethodReplacementProvider registry.
  28. /// </summary>
  29. /// <returns>
  30. /// A <see cref="IMethodReplacementProvider" /> that will determine the code that will be executed once a target
  31. /// method is called.
  32. /// </returns>
  33. public static void SetProvider(IMethodReplacementProvider provider)
  34. {
  35. lock (_lock)
  36. {
  37. _provider = provider;
  38. }
  39. }
  40. }
  41. }