Wpf,Unity6
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Prism" version="5.0.0" targetFramework="net452" />
<package id="Prism.Composition" version="5.0.0" targetFramework="net452" />
<package id="Prism.Interactivity" version="5.0.0" targetFramework="net452" />
<package id="Prism.Mvvm" version="1.0.0" targetFramework="net452" />
<package id="Prism.PubSubEvents" version="1.0.0" targetFramework="net452" />
<package id="CommonServiceLocator" version="1.2" targetFramework="net452" />
<package id="Prism.UnityExtensions" version="5.0.1" targetFramework="net452" />
<package id="Unity" version="3.5.1404.0" targetFramework="net452" />
</packages>
using Microsoft.Practices.Prism.UnityExtensions; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using Microsoft.Practices.Prism.Modularity; using MA; using MB; namespace WpfApplication6 { public class WpfBootstrapper:UnityBootstrapper { protected override DependencyObject CreateShell() { return Container.TryResolve<Shell>(); } protected override void ConfigureModuleCatalog() { base.ConfigureModuleCatalog(); ModuleCatalog moduleCatalog = (ModuleCatalog)this.ModuleCatalog; moduleCatalog.AddModule(typeof(ModuleA)); moduleCatalog.AddModule(typeof(ModuleB)); } protected override IModuleCatalog CreateModuleCatalog() { return base.CreateModuleCatalog(); } protected override void InitializeShell() { base.InitializeShell(); App.Current.MainWindow = (Window)this.Shell; App.Current.MainWindow.Show(); } } }
using Microsoft.Practices.Prism.Modularity; using Microsoft.Practices.Prism.Regions; using Microsoft.Practices.Unity; using MA.Views; using MA.ViewModel; namespace MA { public class ModuleA : IModule { private readonly IRegionManager _regionManager; private readonly IUnityContainer _container; public ModuleA(IUnityContainer container,IRegionManager regionManager) { _container = container; _regionManager = regionManager; } public void Initialize() { _container.RegisterType<IGetStudentList, StudentVM>(new ContainerControlledLifetimeManager()); this._regionManager.RegisterViewWithRegion("MARegion",typeof(MAView)); } } }
<UserControl x:Class="MA.Views.MAView" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:MA.Views" mc:Ignorable="d" d:DesignHeight="100" d:DesignWidth="300"> <Grid Background="Red"> <DataGrid x:Name="dg" ItemsSource="{Binding StuList}" AutoGenerateColumns="True" BorderBrush="Yellow" BorderThickness="5"> </DataGrid> </Grid> </UserControl>