Wednesday, March 23, 2016

Prism bootstraping Shell, Module, Region vs Fusion Bootstrapping Designer

Prism has multiple extension points for injecting Shell, Module, Region with boiler template code. Fusion replaces these with Bootstrapper Extension where pre-configure shell pop up. It can bootstrap anything including module and regions through GUI asset manager instead of code. It also abstract away Data pipe as Data Provider, though data still can come through directly such as in Raw Socket Connection. But it only makes sense if avoid Data Provider pattern has other benefit such as performance or less code

Here is how Prism bootstrap

Shell:   <ContentControl prism:RegionManager.RegionName="R1" />

Module: (Separate Wpf User Control Project since classLib gives winForm ctx menu)
public class ModuleA : IModule::Init(){ _regMgr.RegisterViewWithRegion("R1",typeof(MWView));}

Unity/MefBootstrapper: 

(0) OnStartup() { 
    bootstrapper.Run(); 
          //System.ComponentModelComposition.dll,MSMefExtension.dll, unity.dll
    } 

(1) CreateShell()
    {
        return Container.Resolve<Shell>();
        return Container.GetExportedValue<Shell>();     }
    [Export] public partial class Shell : Window

(2) InitializeShell()
{
     App.Current.MainWindow=(Window) Shell;
     App.Current.MainWindow.Show();   
}

(3) ConfigureAggregateCalalog --- MEF Bootstrapping
     AggregateCatalog.Catalogs.Add(new AssemblyCatalog(typeof(Bootstrapper).Assembly));

(4) ConfigureModuleCatalog  --load module in code
{
  Type t=typeof(ModuleAModule) // add ref to solution;
  ModuleCatalog.AddModule( new ModuleInfo(){ ModuleName=t.Name,
    ModuleType=t.AssemblyQualifiedName,
    InitializatinMod=WhenAvailable});
}

(5) ConfigureAggregateCalalog --load MEF module in code as MEF in (3)
AggregateCatalog.Catalogs.Add(typeof(ModuleAModule).Assembly);
[ModuleExport(typeof(ModuleAModule),InitializationMode=] public ModuleAModule

(6) CreateModuleCatalog --- load by directory
     return new DirectoryModuleCatalog() {ModulePath=".\Modules"};
     [Moldule(ModuleName="ModuleA",OnDemand=True)] public ModuleAModule

(7) CreateModuleCatalog --- load by resource.xaml
     return ModuleCatalog.CreateFromXaml(new Uri("/Proj;component/m.xaml",UriKind.Abs));

<Modulelarity:ModuleCatalog>
    <Modularity:ModuleInfo Ref="file://ModuleA.dll" ModuleName="ModuleA" 
       ModuleType="ModuleA.ModuleAModule, ModuleA, Version=1.0.0.0" InitMod />

(8) CreateModuleCatalog --- load by app.config
  return new ConfigurationModuleCatalog();

<configSections> <section name="modules"  type=ModulesConfigurationSection />

<modules>
    <module  assemblyFile="Modules/ModuleA.dll" moduleName="ModuleA"
moduleType="ModuleA.ModuleAModule, ModuleA, Version=1.0.0.0, Culture=neutral, 
PublicKeyToken=null" startupLoaded="true" />


(9) IModule.Initialize() --- all your code Reg type, sub services, compose view

No comments:

Post a Comment