/src/LinFu.IoC/Configuration/Loaders/Loader.cs

http://github.com/philiplaureano/LinFu · C# · 54 lines · 30 code · 9 blank · 15 comment · 4 complexity · c05dc132dd775a5928b8f425fc04c4b4 MD5 · raw file

  1. using System.Reflection;
  2. using LinFu.IoC.Interfaces;
  3. using LinFu.Reflection;
  4. namespace LinFu.IoC.Configuration
  5. {
  6. /// <summary>
  7. /// Represents a class that can dynamically configure
  8. /// <see cref="IServiceContainer" /> instances at runtime.
  9. /// </summary>
  10. public class Loader : Loader<IServiceContainer>
  11. {
  12. private readonly AssemblyContainerLoader _containerLoader;
  13. /// <summary>
  14. /// Initializes the loader using the default values.
  15. /// </summary>
  16. public Loader()
  17. {
  18. _containerLoader = this.CreateDefaultContainerLoader();
  19. // Load everything else into the container
  20. var hostAssembly = typeof(Loader).Assembly;
  21. QueuedActions.Add(container => container.LoadFrom(hostAssembly));
  22. // Make sure that the plugins are only added once
  23. if (!Plugins.HasElementWith(p => p is AutoPropertyInjector))
  24. Plugins.Add(new AutoPropertyInjector());
  25. if (!Plugins.HasElementWith(p => p is AutoMethodInjector))
  26. Plugins.Add(new AutoMethodInjector());
  27. if (!Plugins.HasElementWith(p => p is AutoFieldInjector))
  28. Plugins.Add(new AutoFieldInjector());
  29. // Add the initializer to the end of
  30. // the instantiation pipeline
  31. if (!Plugins.HasElementWith(p => p is InitializerPlugin))
  32. Plugins.Add(new InitializerPlugin());
  33. FileLoaders.Add(_containerLoader);
  34. }
  35. /// <summary>
  36. /// Gets or sets the value indicating the <see cref="IAssemblyLoader" /> instance
  37. /// that will be used to load assemblies into memory.
  38. /// </summary>
  39. public IAssemblyLoader<Assembly> AssemblyLoader
  40. {
  41. get => _containerLoader.AssemblyLoader;
  42. set => _containerLoader.AssemblyLoader = value;
  43. }
  44. }
  45. }