PageRenderTime 81ms CodeModel.GetById 76ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/src/LinFu.AOP.Interfaces/AroundInvokeMethodCallRegistry.cs

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