You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/mvvm/MigratingFromMvvmLight.md
+253-2Lines changed: 253 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,9 @@ dev_langs:
9
9
10
10
# Migrating from MvvmLight
11
11
12
-
This article outlines some of the key differences between the [MvvmLight Toolkit](https://github.com/lbugnion/mvvmlight) and the Windows Community Toolkit MVVM framework to ease your migration.
12
+
This article outlines some of the key differences between the [MvvmLight Toolkit](https://github.com/lbugnion/mvvmlight) and the MVVM Toolkit to ease your migration.
13
+
14
+
While this article specifically focuses on the migrations from MvvmLight to the MVVM Toolkit, note that there are additional improvements that have been made within the MVVM Toolkit so I highly recommend taking a look at the documentation for the APIs.
13
15
14
16
## Installing the WCT MVVM Toolkit
15
17
@@ -307,7 +309,7 @@ var isInDesignMode = ViewModelBase.IsInDesignModeStatic;
307
309
// No direct replacement, remove
308
310
```
309
311
310
-
## SimpleIoc
312
+
## Migrating SimpleIoc
311
313
312
314
The [IoC](Ioc) implementation in the MVVM Toolkit takes advantage of existing .NET APIs through the `Microsoft.Extensions.DependencyInjection` library.
The following steps focus on migrating your existing components which take advantage of the `Messenger` of the MvvmLight Toolkit.
416
+
417
+
The Windows Community Toolkit MVVM framework provides a [`Messenger`](Messenger) type that provides similar functionality.
418
+
419
+
A note on `Register` methods throughout this migration. MvvmLight uses weak references to establish the link between the `Messenger` instance and the recipient. This is not required by the MVVM Toolkit implementation and if this optional parameter has been set to `true` in any of your `Register` method calls, this will be removed.
420
+
421
+
Below are a list of migrations that will need to be performed if being used in your current solution.
The functionality of `Register<TMessage>(object, Action<TMessage>)` can be achieved with the MVVM Toolkit's `IMessenger` extension method `Register<TMessage>(object, Action<TMessage>)`.
There is no direct replacement for this registration mechanism which allows you to support receiving messages for derived message types also. This change is intentional as the `Messenger` implementation aims to not use reflection to achieve it's performance benefits.
440
+
441
+
Alternatively, there are a few options that can be done to achieve this functionality.
442
+
443
+
- Create a custom `IMessenger` implementation
444
+
- Register the additional message types using a shared `Action`
The functionality of `Register<TMessage>(object, object, Action<TMessage>)` can be achieved with the MVVM Toolkit's `Register<TMessage, TToken>(object, TToken, Action<TMessage>)` method.
There is no direct replacement for this registration mechanism which allows you to support receiving messages for derived message types also. This change is intentional as the `Messenger` implementation aims to not use reflection to achieve it's performance benefits.
470
+
471
+
Alternatively, there are a few options that can be done to achieve this functionality.
472
+
473
+
- Create a custom `IMessenger` implementation
474
+
- Register the additional message types using a shared `Action`
The functionality of `Unregister(object)` can be achieved with the MVVM Toolkit's `UnregisterAll(object)` method.
515
+
516
+
```csharp
517
+
// MvvmLight
518
+
Messenger.Default.Unregister(this);
519
+
520
+
// Toolkit.Mvvm
521
+
Messenger.Default.UnregisterAll(this);
522
+
```
523
+
524
+
#### Unregister<TMessage> ( object )
525
+
526
+
The functionality of `Unregister<TMessage>(object)` can be achieved with the MVVM Toolkit's `IMessenger` extension method `Unregister<TMessage>(object)`.
The functionality of `Unregister<TMessage>(object, object)` can be achieved with the MVVM Toolkit's `Unregister<TMessage, TToken>(object, TToken)` method.
There is no direct replacement for the `Cleanup` method in the MVVM Toolkit. In the context of MvvmLight, `Cleanup` is used to remove registrations which are no longer alive as the implementation takes advantage of weak references.
579
+
580
+
Any calls to the `Cleanup` method can be removed.
581
+
582
+
```csharp
583
+
// MvvmLight
584
+
Messenger.Default.Cleanup();
585
+
586
+
// Toolkit.Mvvm
587
+
// No direct replacement, remove
588
+
```
589
+
590
+
#### RequestCleanup ()
591
+
592
+
There is no direct replacement for the `RequestCleanup` method in the MVVM Toolkit. In the context of MvvmLight, `RequestCleanup` is used to initiate a request to remove registrations which are no longer alive as the implementation takes advantage of weak references.
593
+
594
+
Any calls to the `RequestCleanup` method can be removed.
595
+
596
+
```csharp
597
+
// MvvmLight
598
+
Messenger.Default.RequestCleanup();
599
+
600
+
// Toolkit.Mvvm
601
+
// No direct replacement, remove
602
+
```
603
+
604
+
#### ResetAll ()
605
+
606
+
There is no direct replacement for the `ResetAll` method in the MVVM Toolkit. In the context of MvvmLight, this method is used to reset the default `IMessenger` instance by calling the static `Reset` method.
607
+
608
+
Any calls to the `ResetAll()` method can be removed.
609
+
610
+
```csharp
611
+
// MvvmLight
612
+
Messenger.Default.ResetAll();
613
+
614
+
// Toolkit.Mvvm
615
+
// No direct replacement, remove
616
+
```
617
+
618
+
### Messenger Static Methods
619
+
620
+
#### OverrideDefault ( IMessenger )
621
+
622
+
There is no direct replacement for the `OverrideDefault(IMessenger)` method in the MVVM Toolkit.
623
+
624
+
Any calls to the `Messenger.OverrideDefault(IMessenger)` method can be removed.
625
+
626
+
```csharp
627
+
// MvvmLight
628
+
Messenger.OverrideDefault(newMessenger());
629
+
630
+
// Toolkit.Mvvm
631
+
// No direct replacement, remove
632
+
```
633
+
634
+
#### Reset ()
635
+
636
+
There is no direct replacement for the `Reset` method in the MVVM Toolkit. In the context of MvvmLight, this static method is used to reset the default `IMessenger` instance.
637
+
638
+
Any calls to the `Messenger.Reset()` method can be removed.
639
+
640
+
```csharp
641
+
// MvvmLight
642
+
Messenger.Reset();
643
+
644
+
// Toolkit.Mvvm
645
+
// No direct replacement, remove
646
+
```
647
+
648
+
### Messenger Static Properties
649
+
650
+
#### Default
651
+
652
+
`Default` has a direct replacement, `Default`, requiring no change to your existing implementation.
0 commit comments