/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

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