Ejemplo n.º 1
0
            internal static StilettoContainer MakeContainer(
                StilettoContainer baseContainer,
                IPlugin plugin,
                params object[] modules)
            {
                var entryPoints = new Dictionary <string, Type>(Key.Comparer);
                var bindings    = new Dictionary <string, Binding>(Key.Comparer);
                var overrides   = new Dictionary <string, Binding>(Key.Comparer);

                foreach (var runtimeModule in GetAllRuntimeModules(plugin, modules).Values)
                {
                    var addTo = runtimeModule.IsOverride ? overrides : bindings;

                    foreach (var key in runtimeModule.EntryPoints)
                    {
                        entryPoints.Add(key, runtimeModule.Module.GetType());
                    }

                    runtimeModule.GetBindings(addTo);
                }

                var resolver = new Resolver(
                    baseContainer != null ? baseContainer.resolver : null,
                    plugin,
                    HandleErrors);

                resolver.InstallBindings(bindings);
                resolver.InstallBindings(overrides);

                return(new StilettoContainer(baseContainer, resolver, plugin, entryPoints));
            }
Ejemplo n.º 2
0
        public static Container CreateWithPlugins(object[] modules, IPlugin[] plugins)
        {
            var allPlugins = new IPlugin[plugins.Length + 2];

            Array.Copy(plugins, allPlugins, plugins.Length);
            allPlugins[plugins.Length]     = new CodegenPlugin();
            allPlugins[plugins.Length + 1] = new ReflectionPlugin();
            return(StilettoContainer.MakeContainer(null, new RuntimeAggregationPlugin(allPlugins), modules));
        }
Ejemplo n.º 3
0
        public static Container CreateWithLoaders(object[] modules, ILoader[] loaders)
        {
            var allLoaders = new ILoader[loaders.Length + 2];

            Array.Copy(loaders, allLoaders, loaders.Length);
            allLoaders[loaders.Length]     = new CodegenLoader();
            allLoaders[loaders.Length + 1] = new ReflectionLoader();
            return(StilettoContainer.MakeContainer(null, new RuntimeAggregationLoader(allLoaders), modules));
        }
Ejemplo n.º 4
0
 private StilettoContainer(
     StilettoContainer baseContainer,
     Resolver resolver,
     IPlugin plugin,
     IDictionary <string, Type> entryPoints)
 {
     this.baseContainer = baseContainer;
     this.resolver      = resolver;
     this.plugin        = plugin;
     this.entryPoints   = entryPoints;
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a container with the given modules, of which at least one
        /// must be given.
        /// </summary>
        /// <param name="modules">
        /// One or more modules, which may be either a <see cref="Type"/> that
        /// is decorated with a <see cref="ModuleAttribute"/>, or an instance
        /// of such a type.
        /// </param>
        /// <returns>
        /// Returns a <see cref="Container"/> which satisfies the requirements
        /// of the given modules, if possible.
        /// </returns>
        public static Container Create(params object[] modules)
        {
            var plugins = ReflectionUtils.GetCompiledPlugins();

            plugins.Add(new CodegenPlugin());
            plugins.Add(new ReflectionPlugin());

            var plugin = new RuntimeAggregationPlugin(plugins.ToArray());

            return(StilettoContainer.MakeContainer(null, plugin, modules));
        }
Ejemplo n.º 6
0
 private StilettoContainer(
     StilettoContainer baseContainer,
     Resolver resolver,
     ILoader loader,
     IDictionary <string, Type> injectTypes)
 {
     this.baseContainer = baseContainer;
     this.resolver      = resolver;
     this.loader        = loader;
     this.injectTypes   = injectTypes;
 }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a container with the given modules, of which at least one
        /// must be given.
        /// </summary>
        /// <param name="modules">
        /// One or more modules, which may be either a <see cref="Type"/> that
        /// is decorated with a <see cref="ModuleAttribute"/>, or an instance
        /// of such a type.
        /// </param>
        /// <returns>
        /// Returns a <see cref="Container"/> which satisfies the requirements
        /// of the given modules, if possible.
        /// </returns>
        public static Container Create(params object[] modules)
        {
            var loaders = ReflectionUtils.GetCompiledLoaders();

            loaders.Add(new CodegenLoader());
            loaders.Add(new ReflectionLoader());

            var loader = new RuntimeAggregationLoader(loaders.ToArray());

            return(StilettoContainer.MakeContainer(null, loader, modules));
        }