Skip to content

Commit efa4163

Browse files
committed
Revert "UWP ViewModels ctor injection"
This reverts commit 8ef8f4c.
1 parent 8ef8f4c commit efa4163

31 files changed

+55
-144
lines changed

samples/MvvmSampleUwp/App.xaml.cs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111
using Refit;
1212
using MvvmSampleUwp.Helpers;
1313
using MvvmSample.Core.Services;
14-
using MvvmSample.Core.ViewModels.Widgets;
15-
using MvvmSample.Core.ViewModels;
16-
14+
1715
namespace MvvmSampleUwp
1816
{
1917
/// <summary>
@@ -43,20 +41,10 @@ protected override void OnLaunched(LaunchActivatedEventArgs e)
4341

4442
// Register services
4543
Ioc.Default.ConfigureServices(
46-
new ServiceCollection()
47-
//Services
44+
new ServiceCollection()
4845
.AddSingleton<IFilesService, FilesService>()
4946
.AddSingleton<ISettingsService, SettingsService>()
50-
.AddSingleton(RestService.For<IRedditService>("https://www.reddit.com/"))
51-
//ViewModels
52-
.AddTransient<PostWidgetViewModel>()
53-
.AddTransient<SubredditWidgetViewModel>()
54-
.AddTransient<AsyncRelayCommandPageViewModel>()
55-
.AddTransient<IocPageViewModel>()
56-
.AddTransient<MessengerPageViewModel>()
57-
.AddTransient<ObservableObjectPageViewModel>()
58-
.AddTransient<RelayCommandPageViewModel>()
59-
.AddTransient<SamplePageViewModel>()
47+
.AddSingleton(RestService.For<IRedditService>("https://www.reddit.com/"))
6048
.BuildServiceProvider());
6149
}
6250

samples/MvvmSampleUwp/Views/AsyncRelayCommandPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313
xmlns:converters="using:Microsoft.Toolkit.Uwp.UI.Converters"
1414
mc:Ignorable="d"
1515
NavigationCacheMode="Enabled">
16+
<Page.DataContext>
17+
<viewModels:AsyncRelayCommandPageViewModel x:Name="ViewModel"/>
18+
</Page.DataContext>
1619
<interactivity:Interaction.Behaviors>
1720
<core:EventTriggerBehavior EventName="Loaded">
1821
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="AsyncRelayCommand"/>

samples/MvvmSampleUwp/Views/AsyncRelayCommandPage.xaml.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using MvvmSample.Core.ViewModels;
75
using Windows.UI.Xaml.Controls;
86

97
namespace MvvmSampleUwp.Views
@@ -15,13 +13,7 @@ public sealed partial class AsyncRelayCommandPage : Page
1513
{
1614
public AsyncRelayCommandPage()
1715
{
18-
this.InitializeComponent();
19-
20-
ViewModel = Ioc.Default.GetRequiredService<AsyncRelayCommandPageViewModel>();
21-
22-
DataContext = ViewModel;
16+
this.InitializeComponent();
2317
}
24-
25-
public AsyncRelayCommandPageViewModel ViewModel { get; }
2618
}
2719
}

samples/MvvmSampleUwp/Views/BuildingTheUIPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
1111
mc:Ignorable="d"
1212
NavigationCacheMode="Enabled">
13+
<Page.DataContext>
14+
<viewModels:SamplePageViewModel x:Name="ViewModel"/>
15+
</Page.DataContext>
1316
<interactivity:Interaction.Behaviors>
1417
<core:EventTriggerBehavior EventName="Loaded">
1518
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="PuttingThingsTogether"/>

samples/MvvmSampleUwp/Views/BuildingTheUIPage.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using MvvmSample.Core.ViewModels;
75
using Windows.UI.Xaml.Controls;
86

97
namespace MvvmSampleUwp.Views
@@ -16,12 +14,6 @@ public sealed partial class BuildingTheUIPage : Page
1614
public BuildingTheUIPage()
1715
{
1816
this.InitializeComponent();
19-
20-
ViewModel = Ioc.Default.GetRequiredService<SamplePageViewModel>();
21-
22-
DataContext = ViewModel;
2317
}
24-
25-
public SamplePageViewModel ViewModel { get; }
2618
}
2719
}

samples/MvvmSampleUwp/Views/IntroductionPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
xmlns:interactivity="using:Microsoft.Xaml.Interactivity"
1111
mc:Ignorable="d"
1212
NavigationCacheMode="Enabled">
13+
<Page.DataContext>
14+
<viewModels:ObservableObjectPageViewModel x:Name="ViewModel"/>
15+
</Page.DataContext>
1316
<interactivity:Interaction.Behaviors>
1417
<core:EventTriggerBehavior EventName="Loaded">
1518
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="Introduction"/>

samples/MvvmSampleUwp/Views/IntroductionPage.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using MvvmSample.Core.ViewModels;
75
using Windows.UI.Xaml.Controls;
86

97
namespace MvvmSampleUwp.Views
@@ -16,12 +14,6 @@ public sealed partial class IntroductionPage : Page
1614
public IntroductionPage()
1715
{
1816
this.InitializeComponent();
19-
20-
ViewModel = Ioc.Default.GetRequiredService<ObservableObjectPageViewModel>();
21-
22-
DataContext = ViewModel;
2317
}
24-
25-
public ObservableObjectPageViewModel ViewModel { get; }
2618
}
2719
}

samples/MvvmSampleUwp/Views/IocPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
1111
mc:Ignorable="d"
1212
NavigationCacheMode="Enabled">
13+
<Page.DataContext>
14+
<viewModels:IocPageViewModel x:Name="ViewModel"/>
15+
</Page.DataContext>
1316
<interactivity:Interaction.Behaviors>
1417
<core:EventTriggerBehavior EventName="Loaded">
1518
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="Ioc"/>

samples/MvvmSampleUwp/Views/IocPage.xaml.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using CommunityToolkit.Mvvm.DependencyInjection;
6-
using MvvmSample.Core.ViewModels;
75
using Windows.UI.Xaml.Controls;
86

97
namespace MvvmSampleUwp.Views
@@ -16,12 +14,6 @@ public sealed partial class IocPage : Page
1614
public IocPage()
1715
{
1816
this.InitializeComponent();
19-
20-
ViewModel = Ioc.Default.GetRequiredService<IocPageViewModel>();
21-
22-
DataContext = ViewModel;
2317
}
24-
25-
public IocPageViewModel ViewModel { get; }
2618
}
2719
}

samples/MvvmSampleUwp/Views/MessengerPage.xaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
xmlns:core="using:Microsoft.Xaml.Interactions.Core"
1111
mc:Ignorable="d"
1212
NavigationCacheMode="Enabled">
13+
<Page.DataContext>
14+
<viewModels:MessengerPageViewModel x:Name="ViewModel"/>
15+
</Page.DataContext>
1316
<interactivity:Interaction.Behaviors>
1417
<core:EventTriggerBehavior EventName="Loaded">
1518
<core:InvokeCommandAction Command="{x:Bind ViewModel.LoadDocsCommand}" CommandParameter="Messenger"/>

0 commit comments

Comments
 (0)