/// <summary>
        /// Loads the specified modules into the given container.
        /// </summary>
        /// <param name="rootContainer">The container into wich create and add the module published services.</param>
        /// <param name="modulesInfo">The list of modules to load.</param>
        /// <remarks>A <see cref="CompositionContainer"/> is created for every module in the list and added to the
        /// <paramref name="rootContainer"/>. The Load() method is called on every module that
        /// exposes a <see cref="IModuleInitializer"/>.</remarks>
        public void Load(CompositionContainer rootContainer, params IModuleInfo[] modulesInfo)
        {
            Guard.ArgumentNotNull(rootContainer, "compositionContainer");
            Guard.ArgumentNotNull(modulesInfo, "modules");

            foreach (IModuleInfo moduleInfo in modulesInfo)
            {
                Assembly moduleAssembly = Assembly.Load(moduleInfo.AssemblyName);

                CompositionContainer container = String.IsNullOrEmpty(moduleInfo.VirtualPath)
                                                                        ? rootContainer
                                                                        :
                                                 rootContainer.Containers.AddNew <CompositionContainer>(moduleInfo.Name);

                LoadServices(container, moduleInfo);

                foreach (Type t in moduleAssembly.GetTypes())
                {
                    if (typeof(IModuleInitializer).IsAssignableFrom(t))
                    {
                        IModuleInitializer init = (IModuleInitializer)container.BuildNewItem(t);
                        _modules.Add(moduleInfo.Name, init);
                        try
                        {
                            init.Load(container);
                        }
                        catch (Exception ex)
                        {
                            ThrowModuleLoadException(ex, moduleAssembly);
                        }
                    }
                }
            }
        }
示例#2
0
        public void WebApplicationCreatesBuilderThatDoesContainerAwareTypeMapping()
        {
            TestableWebClientApplication app = new TestableWebClientApplication();
            MockHttpContext context          = new MockHttpContext();

            app.TestRun();

            CompositionContainer root = app.RootContainer;

            root.RegisterTypeMapping <IFoo, Foo>();

            IFoo created = (IFoo)(root.BuildNewItem(typeof(IFoo)));

            Assert.IsNotNull(created);
            Assert.IsTrue(created is Foo);
        }