/src/LinFu.IoC/CreatorFromInstance.cs

http://github.com/philiplaureano/LinFu · C# · 36 lines · 16 code · 4 blank · 16 comment · 0 complexity · 211ad2b1fc43414a191eabb7bd93e399 MD5 · raw file

  1. using LinFu.IoC.Interfaces;
  2. namespace LinFu.IoC
  3. {
  4. /// <summary>
  5. /// Represents an <see cref="ICreateInstance" /> type that generates an object instance from an existing instance.
  6. /// </summary>
  7. internal class CreatorFromInstance : ICreateInstance
  8. {
  9. private readonly object _instance;
  10. /// <summary>
  11. /// Initializes the class with the target <paramref name="instance" />.
  12. /// </summary>
  13. /// <param name="instance">The instance that will be returned every time the <see cref="CreateFrom" /> method is called.</param>
  14. internal CreatorFromInstance(object instance)
  15. {
  16. _instance = instance;
  17. }
  18. /// <summary>
  19. /// Returns the object instance that given when the <see cref="CreatorFromInstance" /> class instance was initialized.
  20. /// </summary>
  21. /// <param name="factoryRequest">
  22. /// The <see cref="IFactoryRequest" /> instance that describes the context of the service
  23. /// request.
  24. /// </param>
  25. /// <param name="factory">The <see cref="IFactory" /> instance that will be used to instantiate the service type.</param>
  26. /// <returns>A valid service instance.</returns>
  27. public object CreateFrom(IFactoryRequest factoryRequest, IFactory factory)
  28. {
  29. return _instance;
  30. }
  31. }
  32. }