示例#1
0
        /// <summary>
        /// When loading a prism module (IModule.Initialize), we need to update the IoC container too.
        /// The Autofac.Module will be passed inside the <see cref="ModuleLoadEvent"/> class.
        /// </summary>
        /// <param name="e">Class containing the module configuration to be updated.</param>
        private void PrismModule_OnLoad(IModuleLoadEvent e)
        {
            var updater = new ContainerBuilder();

            updater.RegisterModule(e.Module);
            updater.Update(Container);
        }
示例#2
0
        /// <summary>
        /// Updates the IoC-Container at runtime, when a module is being loaded,
        /// with the module registrations.
        /// </summary>
        protected virtual void RequestContainerUpdate()
        {
            Type[] assemblyTypes = GetType().Assembly.GetTypes();
            Type   type          = assemblyTypes.Single(t => t.IsSubclassOf(typeof(Autofac.Module)));

            Module moduleToLoad = (Module)type.GetConstructor(new Type[0]).Invoke(null);

            IModuleLoadEvent loadEvent = _scope.Resolve <IModuleLoadEvent>();

            loadEvent.Module = moduleToLoad;

            _eventAggregator.GetEvent <PubSubEvent <IModuleLoadEvent> >()
            .Publish(loadEvent);
        }