Skip to content

Commit 76195d3

Browse files
committed
Add simple Prism Unity sample (work in progress)
1 parent 43181f7 commit 76195d3

32 files changed

+1232
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.25420.1
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PrismUnityDemo", "PrismUnityDemo\PrismUnityDemo.csproj", "{99C9E82C-C594-446D-AA59-8FFBC43AD226}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{99C9E82C-C594-446D-AA59-8FFBC43AD226}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{99C9E82C-C594-446D-AA59-8FFBC43AD226}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{99C9E82C-C594-446D-AA59-8FFBC43AD226}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{99C9E82C-C594-446D-AA59-8FFBC43AD226}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/>
5+
</startup>
6+
</configuration>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<Application x:Class="PrismUnityDemo.App"
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
xmlns:local="clr-namespace:PrismUnityDemo">
5+
<Application.Resources>
6+
7+
</Application.Resources>
8+
</Application>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Configuration;
4+
using System.Data;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
using System.Windows;
8+
9+
namespace PrismUnityDemo
10+
{
11+
/// <summary>
12+
/// Interaction logic for App.xaml
13+
/// </summary>
14+
public partial class App : Application
15+
{
16+
protected override void OnStartup(StartupEventArgs e)
17+
{
18+
base.OnStartup(e);
19+
20+
var bootstrapper = new Bootstrapper();
21+
bootstrapper.Run();
22+
}
23+
}
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using Microsoft.Practices.Unity;
2+
using Prism.Modularity;
3+
using Prism.Unity;
4+
using PrismUnityDemo.Data;
5+
using PrismUnityDemo.Modules;
6+
using PrismUnityDemo.ViewModel;
7+
using PrismUnityDemo.Contracts;
8+
using PrismUnityDemo.Views;
9+
using System.Windows;
10+
11+
namespace PrismUnityDemo
12+
{
13+
class Bootstrapper : UnityBootstrapper
14+
{
15+
protected override DependencyObject CreateShell()
16+
{
17+
return Container.Resolve<MainWindow>();
18+
}
19+
20+
protected override void ConfigureContainer()
21+
{
22+
base.ConfigureContainer();
23+
24+
this.Container.RegisterType<MainWindowNavigationController>(
25+
new ContainerControlledLifetimeManager());
26+
this.Container.RegisterType(typeof(ProductMaintenanceViewModel));
27+
this.Container.RegisterTypeForNavigation<ProductDetailView>(nameof(ProductDetailView));
28+
this.Container.RegisterType(typeof(ProductDetailViewModel));
29+
this.Container.RegisterType<GlobalCommands>(new ContainerControlledLifetimeManager());
30+
}
31+
32+
protected override void ConfigureModuleCatalog()
33+
{
34+
this.ModuleCatalog.AddModule(new ModuleInfo
35+
{
36+
ModuleName = "Repository",
37+
ModuleType = typeof(RepositoryModule).AssemblyQualifiedName
38+
});
39+
this.ModuleCatalog.AddModule(new ModuleInfo
40+
{
41+
ModuleName = "Product Maintenance",
42+
ModuleType = typeof(ProductMaintenanceModule).AssemblyQualifiedName
43+
});
44+
}
45+
46+
protected override void InitializeShell()
47+
{
48+
Application.Current.MainWindow.Show();
49+
}
50+
}
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Prism.Events;
2+
3+
namespace PrismUnityDemo.Contracts
4+
{
5+
public class CloseProductDetailEvent : PubSubEvent<IProductDetailViewModel>
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
using Prism.Commands;
2+
3+
namespace PrismUnityDemo.Contracts
4+
{
5+
public class GlobalCommands
6+
{
7+
public GlobalCommands()
8+
{
9+
this.Print = new CompositeCommand(true);
10+
this.PrintAll = new CompositeCommand();
11+
this.Close = new CompositeCommand(true);
12+
}
13+
14+
public CompositeCommand Print { get; private set; }
15+
public CompositeCommand PrintAll { get; private set; }
16+
public CompositeCommand Close { get; private set; }
17+
}
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace PrismUnityDemo.Contracts
2+
{
3+
public interface IProductDetailViewModel
4+
{
5+
Product Product { get; }
6+
}
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.ComponentModel;
2+
3+
namespace PrismUnityDemo.Contracts
4+
{
5+
public class Product : IDataErrorInfo
6+
{
7+
public int ProductNumber { get; set; }
8+
public string ProductName { get; set; }
9+
10+
public string Error
11+
{
12+
get
13+
{
14+
return this["ProductNumber"] + this["ProductName"];
15+
}
16+
}
17+
18+
public string this[string columnName]
19+
{
20+
get
21+
{
22+
switch (columnName)
23+
{
24+
case "ProductNumber":
25+
if (this.ProductNumber < 0)
26+
{
27+
return "Product number must not be negative.";
28+
}
29+
break;
30+
default:
31+
break;
32+
}
33+
34+
return string.Empty;
35+
}
36+
}
37+
}
38+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using Prism.Events;
2+
3+
namespace PrismUnityDemo.Contracts
4+
{
5+
public class ProductSelectionChangedEvent : PubSubEvent<Product>
6+
{
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System.Collections.Generic;
2+
using System.Linq;
3+
4+
namespace PrismUnityDemo.Contracts
5+
{
6+
public abstract class Repository
7+
{
8+
public abstract IQueryable<Product> SelectAllProducts();
9+
}
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using PrismUnityDemo.Contracts;
2+
using System.Linq;
3+
4+
namespace PrismUnityDemo.Data
5+
{
6+
public class MemoryRepository : Repository
7+
{
8+
private Product[] sampleProducts = new[] {
9+
new Product() { ProductNumber = 1, ProductName = "Twisted Drill" },
10+
new Product() { ProductNumber = 2, ProductName = "Indexable Drill" },
11+
new Product() { ProductNumber = 3, ProductName = "Slot Miller" }
12+
};
13+
14+
public override IQueryable<Product> SelectAllProducts()
15+
{
16+
return this.sampleProducts.AsQueryable();
17+
}
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using Microsoft.Practices.Unity;
2+
using Prism.Modularity;
3+
using PrismUnityDemo.Contracts;
4+
using PrismUnityDemo.Data;
5+
6+
namespace PrismUnityDemo.Data
7+
{
8+
public class RepositoryModule : IModule
9+
{
10+
private IUnityContainer container;
11+
12+
public RepositoryModule(IUnityContainer container)
13+
{
14+
this.container = container;
15+
}
16+
17+
public void Initialize()
18+
{
19+
// Add some code to configure appropriate repository implementation
20+
var memRepo = new MemoryRepository();
21+
22+
this.container.RegisterInstance<Repository>(new MemoryRepository());
23+
}
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using Prism.Modularity;
2+
using Prism.Regions;
3+
using PrismUnityDemo.Views;
4+
5+
namespace PrismUnityDemo.Modules
6+
{
7+
public class ProductMaintenanceModule : IModule
8+
{
9+
private readonly IRegionManager regionManager;
10+
11+
public ProductMaintenanceModule(IRegionManager regionManager)
12+
{
13+
this.regionManager = regionManager;
14+
}
15+
16+
public void Initialize()
17+
{
18+
regionManager.RegisterViewWithRegion(RegionNames.MainContentRegion,
19+
typeof(ProductMaintenanceView));
20+
}
21+
}
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Put your modules here

0 commit comments

Comments
 (0)