/src/LinFu.IoC/Configuration/Resolvers/ConstructorResolver.cs

http://github.com/philiplaureano/LinFu · C# · 51 lines · 27 code · 4 blank · 20 comment · 0 complexity · 38e5d28177103532bb7efa5e96376336 MD5 · raw file

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Reflection;
  4. using LinFu.IoC.Configuration.Interfaces;
  5. using LinFu.IoC.Interfaces;
  6. namespace LinFu.IoC.Configuration
  7. {
  8. /// <summary>
  9. /// Represents the default implementation of the <see cref="IMemberResolver{TMember}" /> class.
  10. /// </summary>
  11. public class ConstructorResolver : MemberResolver<ConstructorInfo>
  12. {
  13. /// <summary>
  14. /// Initializes the class with the default values.
  15. /// </summary>
  16. public ConstructorResolver()
  17. {
  18. }
  19. /// <summary>
  20. /// Initializes the class using the custom method finder.
  21. /// </summary>
  22. /// <param name="getFinder">The functor that will be used to instantiate the method finder.</param>
  23. public ConstructorResolver(Func<IServiceContainer,
  24. IMethodFinder<ConstructorInfo>> getFinder) : base(getFinder)
  25. {
  26. }
  27. /// <summary>
  28. /// Returns the constructors that belong to the <paramref name="concreteType" />.
  29. /// </summary>
  30. /// <param name="concreteType">The type that contains the list of constructors.</param>
  31. /// <returns>A list of constructors that belong to the <paramref name="concreteType" />.</returns>
  32. protected override IEnumerable<ConstructorInfo> GetMembers(Type concreteType)
  33. {
  34. return concreteType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
  35. }
  36. /// <summary>
  37. /// Returns the parameterless constructor in case the search fails.
  38. /// </summary>
  39. /// <param name="concreteType">The target type that contains the default constructor.</param>
  40. /// <returns>The default constructor.</returns>
  41. protected override ConstructorInfo GetDefaultResult(Type concreteType)
  42. {
  43. return concreteType.GetConstructor(BindingFlags.Public | BindingFlags.Instance, null,
  44. new Type[0], null);
  45. }
  46. }
  47. }