PageRenderTime 25ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/src/LinFu.IoC/Factories/FunctorFactory.cs

http://github.com/philiplaureano/LinFu
C# | 33 lines | 17 code | 4 blank | 12 comment | 0 complexity | 5141c246e48ead824f35e2f9b4f27873 MD5 | raw file
  1. using System;
  2. using LinFu.IoC.Interfaces;
  3. namespace LinFu.IoC.Factories
  4. {
  5. /// <summary>
  6. /// A class that converts a delegate into an <see cref="IFactory" /> instance.
  7. /// </summary>
  8. public class FunctorFactory : IFactory
  9. {
  10. private readonly Func<IFactoryRequest, object> _factoryMethod;
  11. /// <summary>
  12. /// Initializes the class with the given <paramref name="factoryMethod" />.
  13. /// </summary>
  14. /// <param name="factoryMethod">The delegate that will be used to instantiate a type.</param>
  15. public FunctorFactory(Func<IFactoryRequest, object> factoryMethod)
  16. {
  17. _factoryMethod = factoryMethod;
  18. }
  19. /// <summary>
  20. /// Instantiates an object reference using the given factory method.
  21. /// </summary>
  22. /// <param name="request">The <see cref="IFactoryRequest" /> instance that describes the requested service.</param>
  23. /// <returns>A non-null object reference that represents the service type.</returns>
  24. public object CreateInstance(IFactoryRequest request)
  25. {
  26. return _factoryMethod(request);
  27. }
  28. }
  29. }