PageRenderTime 82ms CodeModel.GetById 40ms app.highlight 3ms RepoModel.GetById 38ms app.codeStats 0ms

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