PageRenderTime 207ms CodeModel.GetById 121ms app.highlight 11ms RepoModel.GetById 70ms app.codeStats 0ms

/src/LinFu.AOP.Interfaces/AroundMethodBodyRegistry.cs

http://github.com/philiplaureano/LinFu
C# | 57 lines | 36 code | 6 blank | 15 comment | 4 complexity | 12d1c1f5081f793c8a0afefd49044afa MD5 | raw file
 1using System.Collections.Generic;
 2using System.Linq;
 3
 4namespace LinFu.AOP.Interfaces
 5{
 6    /// <summary>
 7    ///     Represents a registry class that handles all class-level interception operations for all modified types.
 8    /// </summary>
 9    public static class AroundMethodBodyRegistry
10    {
11        private static readonly List<IAroundInvokeProvider> _providers = new List<IAroundInvokeProvider>();
12        private static readonly object _lock = new object();
13        private static readonly BootStrapRegistry _registry = BootStrapRegistry.Instance;
14
15        /// <summary>
16        ///     Obtains the <see cref="IAroundInvoke" /> instance for the given <paramref name="context" />.
17        /// </summary>
18        /// <param name="context">The <see cref="IInvocationInfo" /> instance that describes the current method call.</param>
19        /// <returns>An <see cref="IAroundInvoke" /> instance that will be used to wrap a method call or method body.</returns>
20        public static IAroundInvoke GetSurroundingImplementation(IInvocationInfo context)
21        {
22            var resultList = (from p in _providers
23                where p != null
24                let aroundInvoke = p.GetSurroundingImplementation(context)
25                where aroundInvoke != null
26                select aroundInvoke).ToList();
27
28            if (resultList.Count == 0)
29                return null;
30
31            return new CompositeAroundInvoke(resultList);
32        }
33
34        /// <summary>
35        ///     Adds an <see cref="IAroundInvokeProvider" /> to the list of provider instances.
36        /// </summary>
37        /// <param name="provider">The <see cref="IAroundInvokeProvider" /> instance.</param>
38        public static void AddProvider(IAroundInvokeProvider provider)
39        {
40            lock (_lock)
41            {
42                _providers.Add(provider);
43            }
44        }
45
46        /// <summary>
47        ///     Clears the list of <see cref="IAroundInvokeProvider" /> instances.
48        /// </summary>
49        public static void Clear()
50        {
51            lock (_lock)
52            {
53                _providers.Clear();
54            }
55        }
56    }
57}