Search code examples
c#.netwpfprism-7

Prism 7.0 Registering Modules Using a Configuration File


Im trying a hello world program in Prism.Wpf 7.0. Im trying to load a module from app.config file. Which is not working. Im using PrismApplication since UnityBootstrapper is Obsolete in Prism.Wpf 7.0.

My app.config as..

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="modules" type="Prism.Modularity.ModulesConfigurationSection, Prism.Wpf" />
  </configSections>
  <startup>
  </startup>
  <modules>
    <module assemblyFile="ModuleA.dll" moduleType="ModuleA.ModuleAModule, ModuleA, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" moduleName="ModuleAModule" startupLoaded="True" />
  </modules>
</configuration>

My app.xaml.cs as..

internal partial class App : PrismApplication
    {
        //ShellView _tempShellView;
        protected override Window CreateShell()
        {
            var _tempShellView = Container.Resolve<ShellView>();
            var _tempDataContext = Container.Resolve<ShellViewModel>();
            _tempDataContext.ShellWindowClose = new Action(() => _tempShellView.Close());
            _tempShellView.DataContext = _tempDataContext;
            _tempDataContext.Initialize();

            return _tempShellView;
        }

        protected override void InitializeShell(System.Windows.Window shell)
        {
            shell.Show();
        }

        protected override IModuleCatalog CreateModuleCatalog()
        {
            return new ConfigurationModuleCatalog();
            //return  new DirectoryModuleCatalog() {  ModulePath = Environment.CurrentDirectory };
        }
    }

my ModuleAModule.cs as..

public class ModuleAModule : IModule
    {
        IRegionManager _regionManager;

        public ModuleAModule(RegionManager regionManager)
        {
            _regionManager = regionManager;
        }

        public void Initialize()
        {
            _regionManager.RegisterViewWithRegion("ContentRegion", typeof(ViewA));
        }
    }

When i try this code with 6.3 its working on UnityBootstrapper. Need help on this Prism.Wpf 7.0


Solution

  • Guys thanks for viewing my post.. No i got working code.. here is my github sample code