Prism框架(二)——Prism应用程序初始化

Bootstrapper主要用来初始化Prism应用程序,其处理流程如图:

在Prism应用中,Bootstrapper的开发过程如下:
override基类的Bootstrapper
Unity基类提供了UnityBootstrapper和MefBootstrapper,可以根据实际的应用选用不同的Bootstrapper。
[csharp] 
class DirectorBootstrapper : UnityBootstrapper 
    { 
        protected override System.Windows.DependencyObject CreateShell() 
        { 
            return Container.Resolve<Shell>();  
        } 
 
        protected override void InitializeShell() 
        { 
            Application.Current.MainWindow = (Window)Shell; 
            Application.Current.MainWindow.Show();  
        } 
    } 
在App类中调用Bootstrapper的Run函数
[csharp] 
public partial class App : Application 
    { 
        protected override void OnStartup(StartupEventArgs e) 
        { 
            base.OnStartup(e); 
 
            DirectorBootstrapper bootstrapper = new DirectorBootstrapper(); 
            bootstrapper.Run();  
        } 
    } 
配置ModuleCatalog
下面的代码使用plug in模式,将Module配置在Shell中。
[csharp] 
protected override IModuleCatalog CreateModuleCatalog() 
        { 
            ModuleCatalog catalog = new ConfigurationModuleCatalog(); 
            return catalog; 
        } 

[html
< configSections> 
    <section name="modules" type="Microsoft.Practices.Prism.Modularity.ModulesConfigurationSection, Microsoft.Practices.Prism"/> 
  </configSections> 
 
  <modules> 
    <module assemblyFile="Modules.DeviceManager.dll"  
            moduleType="Modules.DeviceManager.DeviceManagerModule, Modules.DeviceManager"  
            moduleName="DeviceManagerModule"/> 
  </modules> 
实现模块接口
[csharp]
public class DeviceManagerModule : IModule 
    { 
        private IUnityContainer unityContainer; 
        private IRegionManager regionManager;  
 
        public DeviceManagerModule(IUnityContainer container, IRegionManager regionManager) 
        { 
            this.unityContainer = container; 
            this.regionManager = regionManager;  
        } 
 
        #region IModule Members 
 
        /// <summary> 
        /// IModule interface method called on module loading. 
        /// </summary> 
        public void Initialize() 
        { 
            this.regionManager.RegisterViewWithRegion(RegionNames.MainRegion, 
                () => this.unityContainer.Resolve<DeviceView>("DeviceView"));  
        } 
 
        #endregion 
    } 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值