PageRenderTime 172ms CodeModel.GetById 80ms app.highlight 2ms RepoModel.GetById 89ms app.codeStats 0ms

/src/LinFu.IoC/CompositePostProcessor.cs

http://github.com/philiplaureano/LinFu
C# | 49 lines | 24 code | 5 blank | 20 comment | 2 complexity | bc3a7968e3f891dc3bb29959d27daf15 MD5 | raw file
 1using System.Collections.Generic;
 2using System.Linq;
 3using LinFu.IoC.Interfaces;
 4
 5namespace LinFu.IoC
 6{
 7    /// <summary>
 8    ///     Represents an <see cref="IPostProcessor" /> type that processes multiple <see cref="IPostProcessor" /> instances at
 9    ///     once.
10    /// </summary>
11    internal class CompositePostProcessor : IPostProcessor
12    {
13        private readonly IEnumerable<IPostProcessor> _postProcessors;
14
15        /// <summary>
16        ///     Initializes the type using the given <paramref name="postProcessors" />.
17        /// </summary>
18        /// <param name="postProcessors">The list of <see cref="IPostProcessor" /> instances that will be handled by this type.</param>
19        internal CompositePostProcessor(IEnumerable<IPostProcessor> postProcessors)
20        {
21            _postProcessors = postProcessors;
22        }
23
24
25        /// <summary>
26        ///     A method that passes every request result made
27        ///     to the list of postprocessors.
28        /// </summary>
29        /// <param name="result">
30        ///     The <see cref="IServiceRequestResult" /> instance that describes the result of the service
31        ///     request.
32        /// </param>
33        /// <returns>A <see cref="IServiceRequestResult" /> representing the results returned as a result of the postprocessors.</returns>
34        public void PostProcess(IServiceRequestResult result)
35        {
36            // Let each postprocessor inspect 
37            // the results and/or modify the 
38            // returned object instance
39            var postprocessors = _postProcessors.ToArray();
40            foreach (var postProcessor in postprocessors)
41            {
42                if (postProcessor == null)
43                    continue;
44
45                postProcessor.PostProcess(result);
46            }
47        }
48    }
49}