/src/LinFu.IoC/Factories/InstanceFactory.cs

http://github.com/philiplaureano/LinFu · C# · 34 lines · 16 code · 4 blank · 14 comment · 0 complexity · 0a9cbf660ce12aff6fe9139c36ec4022 MD5 · raw file

  1. using LinFu.IoC.Interfaces;
  2. namespace LinFu.IoC
  3. {
  4. /// <summary>
  5. /// A factory that uses an existing object reference
  6. /// instead of creating a new service.
  7. /// </summary>
  8. public class InstanceFactory : IFactory
  9. {
  10. private readonly object _instance;
  11. /// <summary>
  12. /// Creates a factory using the existing <paramref name="instance" />.
  13. /// </summary>
  14. /// <param name="instance">The existing object reference that the factory will return.</param>
  15. public InstanceFactory(object instance)
  16. {
  17. _instance = instance;
  18. }
  19. /// <summary>
  20. /// A method that returns the existing object reference associated with
  21. /// this factory.
  22. /// </summary>
  23. /// <param name="request">The <see cref="IFactoryRequest" /> instance that describes the requested service.</param>
  24. /// <returns>A non-null object reference.</returns>
  25. public object CreateInstance(IFactoryRequest request)
  26. {
  27. return _instance;
  28. }
  29. }
  30. }