/src/LinFu.IoC/DefaultCreator.cs

http://github.com/philiplaureano/LinFu · C# · 30 lines · 14 code · 3 blank · 13 comment · 2 complexity · 8e2587b5e8fe3d124ff06502981deee8 MD5 · raw file

  1. using LinFu.IoC.Interfaces;
  2. namespace LinFu.IoC
  3. {
  4. /// <summary>
  5. /// Represents the default implementation for the <see cref="ICreateInstance" />
  6. /// </summary>
  7. public class DefaultCreator : ICreateInstance
  8. {
  9. /// <summary>
  10. /// Creates a service instance using the given <paramref name="factoryRequest" /> and <see cref="IFactory" /> instance.
  11. /// </summary>
  12. /// <param name="factoryRequest">
  13. /// The <see cref="IFactoryRequest" /> instance that describes the context of the service
  14. /// request.
  15. /// </param>
  16. /// <param name="factory">The <see cref="IFactory" /> instance that will be used to instantiate the service type.</param>
  17. /// <returns>A valid service instance.</returns>
  18. public virtual object CreateFrom(IFactoryRequest factoryRequest, IFactory factory)
  19. {
  20. object instance = null;
  21. // Generate the service instance
  22. if (factory != null)
  23. instance = factory.CreateInstance(factoryRequest);
  24. return instance;
  25. }
  26. }
  27. }