-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding Forced option for ViewModelLocationBehavior
- Loading branch information
Showing
6 changed files
with
88 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,33 @@ | ||
namespace Prism.Mvvm; | ||
|
||
/// <summary> | ||
/// Defines the behavior that the <see cref="ViewModelLocator"/> should use. | ||
/// </summary> | ||
public enum ViewModelLocatorBehavior | ||
{ | ||
/// <summary> | ||
/// The ViewModel will be lazily loaded by the Page/Region Navigation Services | ||
/// or the DialogService. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is the default and recommended value for the ViewModelLocator. This will | ||
/// allow the View to be fully initialized and ensure that the proper ViewModel is | ||
/// resolved based on the route name. | ||
/// </remarks> | ||
Automatic, | ||
Disabled | ||
|
||
/// <summary> | ||
/// This will disable Prism's automatic ViewModel Location | ||
/// </summary> | ||
Disabled, | ||
|
||
/// <summary> | ||
/// This is not recommended for most situations | ||
/// </summary> | ||
/// <remarks> | ||
/// This is likely to cause breaks in the Container Scoping. It is recommended that | ||
/// you allow Prism Page/Region Navigation Services or the Dialog Service properly | ||
/// resolve the ViewModel. | ||
/// </remarks> | ||
Forced | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
tests/Maui/Prism.DryIoc.Maui.Tests/Mocks/ViewModels/ForcedViewModel.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using Prism.Common; | ||
|
||
namespace Prism.DryIoc.Maui.Tests.Mocks.ViewModels; | ||
|
||
internal class ForcedViewModel | ||
{ | ||
public ForcedViewModel(IPageAccessor accessor) | ||
{ | ||
_accessor = accessor; | ||
} | ||
|
||
private readonly IPageAccessor _accessor; | ||
|
||
public Page Page => _accessor.Page; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace Prism.DryIoc.Maui.Tests.Mocks.Views; | ||
|
||
internal class ForcedView : ContentPage | ||
{ | ||
public ForcedView() | ||
{ | ||
ViewModelLocator.SetAutowireViewModel(this, ViewModelLocatorBehavior.Forced); | ||
} | ||
} |