migration notes

main
Yik Teng Hie 3 years ago
parent 4454e34b8b
commit a55859937a

@ -8,8 +8,10 @@
* Prism 8 support NET 5 and dotnet Framework. Prism 6.x and below only DotNet Framework 4.8 and below. * Prism 8 support NET 5 and dotnet Framework. Prism 6.x and below only DotNet Framework 4.8 and below.
## Legacy Documentation ## Legacy Documentation
- [Prism 4 Demo](https://www.codeproject.com/Articles/254120/Prism-4-MEF-Application)
- [Prism 5](https://www.microsoft.com/en-sg/download/details.aspx?id=42572) - [Prism 5](https://www.microsoft.com/en-sg/download/details.aspx?id=42572)
- Another nice [link](https://www.cnblogs.com/DoubleChen/p/3687305.html) - Another nice [link](https://www.cnblogs.com/DoubleChen/p/3687305.html)
- Nuget : [Prism 4.1](https://www.nuget.org/packages/prism/4.1.0)
## Migration Guides ## Migration Guides
- [Prism 4.1 to 5](https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ff921144(v=pandp.40)) - [Prism 4.1 to 5](https://learn.microsoft.com/en-us/previous-versions/msp-n-p/ff921144(v=pandp.40))
@ -33,6 +35,40 @@
- Breaking Changes - Breaking Changes
- Removed `Microsoft.Practices` from all namespaces - Removed `Microsoft.Practices` from all namespaces
- Created new xmlns namespace `http://prismlibrary.com/` - Created new xmlns namespace `http://prismlibrary.com/`
- Namespace changes
```cs
// Prism 4
using Microsoft.Practices.Prism;
using Microsoft.Practices.Prism.ViewModel;
// change to Prism 6.3
using Prism.Mvvm
```
```cs
// Prism 4
using Microsoft.Practices.Prism.MefExtensions.Modularity;
using Microsoft.Practices.Prism.Modularity;
// change to Prism 6.3
using Prism.Mef.Modularity;
using Prism.Modularity;
```
```cs
using Microsoft.Practices.Prism.Regions;
// change to
using Prism.Regions
```
```cs
using Microsoft.Practices.Prism.Commands;
// change to
using Prism.Commands;
```
- [Prism 6 to 8](https://prismlibrary.com/docs/wpf/converting-from-6.html) - [Prism 6 to 8](https://prismlibrary.com/docs/wpf/converting-from-6.html)
- Bootstrapper class need to move to Application class - Bootstrapper class need to move to Application class

@ -0,0 +1,4 @@
# Dependency Injection Intro
- DI containers are about two things, R&R (registration and resolving)
- [DI using Normal / MEF / Unity](https://www.c-sharpcorner.com/article/dependency-injection-using-normal-way-vs-mef-vs-unity/)

@ -0,0 +1,4 @@
# Event Aggregator
- [Weak Reference Article](https://michaelscodingspot.com/5-techniques-to-avoid-memory-leaks-by-events-in-c-net-you-should-know/)
-

@ -0,0 +1,55 @@
# Guide on Managed Extensibility Framework (MEF)
- **Note:** Prism 7.2 and above dropped support for MEF. Prefered DI is Unity
- Microsoft ONLY partially port MEF to .NET Core as **Microsoft.Composition** [link](https://www.tutorialspoint.com/dotnet_core/dotnet_core_managed_extensibility_framework.htm#:~:text=You%20can%20use%20MEF%20in,Core%20as%20well%20but%20partially.)
- **Microsoft.Composition** [nuget](https://www.nuget.org/packages/Microsoft.Composition) is also deprecated as legacy
- [Microsoft](https://learn.microsoft.com/en-us/dotnet/framework/mef/)
- [Article 1](https://dailydotnettips.com/setting-up-policies-for-extensible-parts-in-mef/)
- [Article 2](https://www.codeproject.com/Articles/1266833/Let-s-Talk-about-MEF-Part-1)
- [Tim Corey](https://www.codeproject.com/Articles/376033/From-Zero-to-Proficient-with-MEF)
## Creation policy
- Three states of CreationPolicy :
- Shared : This means the object will be shared in the container for any other import statement. This is the default settings for any Export and content can associate with any other component.
- Non-Shared : This means the object will not be shared either directly or indirectly. This is used only when you do not want to share your object and risk being exposed to 3rd party libraries.
- Any : This settings will choose either shared or non-shared value.
- Creation Policy relationship of Import / Export
| Import / Export | Part.Any | Part.Shared | Part.NonShared |
|------------ |----------|-------------|----------------|
| Import.Any | Shared | Shared | Non Shared |
| Import.Shared | Shared | Shared | No Match |
| Import.NonShared | Non Shared | No Match | Non Shared |
## Converting MEF to Unity
- [Reference](http://songhayblog.azurewebsites.net/entry/2017-05-02-wpf-prism-migrating-from-mef-to-unity/)
- Steps
1. Replace MEF [Export] Attributes for Non-Views with Unity Statements
```cs
this._container.RegisterType<IFoo, Foo>(new ContainerControlledLifetimeManager());
```
2. Replace MEF [Export] Attributes for Navigation Views with Prism Statement
```cs
this._container.RegisterTypeForNavigation<FooView>();
```
3. Use Prism XAML Declarations for View-First Patterns
```xml
<UserControl x:Class="MyApp.Views.FooView"
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"
mc:Ignorable="d"
xmlns:prism="http://prismlibrary.com/"
prism:ViewModelLocator.AutoWireViewModel="True">
```
4. Use the GetInstance() Anti-Pattern for View-Model-First Scenarios
```cs
this.GetInstance<IFooViewModel>();
this.GetInstance<IEditorViewModel>($"{nameof(FooView)}Model");
this.GetInstance<IEditorViewModel>($"{this.GetType().Name}Model");
```
Loading…
Cancel
Save