/src/LinFu.IoC/FactoryExtensions.cs

http://github.com/philiplaureano/LinFu · C# · 32 lines · 19 code · 2 blank · 11 comment · 0 complexity · c37d6ba90a2821543f29e69bc5714011 MD5 · raw file

  1. using System;
  2. using LinFu.IoC.Interfaces;
  3. namespace LinFu.IoC
  4. {
  5. /// <summary>
  6. /// Extends the <see cref="IFactory" /> instance with a few helper methods.
  7. /// </summary>
  8. public static class FactoryExtensions
  9. {
  10. /// <summary>
  11. /// Creates an object instance.
  12. /// </summary>
  13. /// <param name="factory">The target factory.</param>
  14. /// <param name="serviceType">The requested service type.</param>
  15. /// <param name="container">The target service contaienr.</param>
  16. /// <param name="additionalArguments">The additional arguments that will be used to create the service instance.</param>
  17. /// <returns>A service instance.</returns>
  18. public static object CreateInstance(this IFactory factory, Type serviceType,
  19. IServiceContainer container, params object[] additionalArguments)
  20. {
  21. var request = new FactoryRequest
  22. {
  23. ServiceName = null,
  24. ServiceType = serviceType,
  25. Arguments = additionalArguments
  26. };
  27. return factory.CreateInstance(request);
  28. }
  29. }
  30. }