Skip to content

Commit ab6bdae

Browse files
committed
Replace GetService with GetRequiredService
1 parent a184ba2 commit ab6bdae

File tree

7 files changed

+10
-10
lines changed

7 files changed

+10
-10
lines changed

IPConfig/App.xaml.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,8 @@ protected override void OnStartup(StartupEventArgs e)
169169
DefaultValue = Current.FindResource(typeof(Window))
170170
});
171171

172-
var mainWindow = Services?.GetService<MainWindow>();
173-
mainWindow!.Show();
172+
var mainWindow = Services.GetRequiredService<MainWindow>();
173+
mainWindow.Show();
174174

175175
base.OnStartup(e);
176176
}
@@ -268,7 +268,7 @@ private void SetupExceptionHandling()
268268

269269
private void ThemeWatcher_WindowsThemeChanged(object? sender, ThemeWatcher.ThemeChangedArgs e)
270270
{
271-
if (Services?.GetService<MainViewModel>()?.CurrentSkinType is null)
271+
if (Services.GetRequiredService<MainViewModel>().CurrentSkinType is null)
272272
{
273273
UpdateSkin(ThemeWatcher.GetCurrentWindowsTheme().ToSkinType());
274274
}

IPConfig/ViewModels/IPConfigListViewModel.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ protected override void OnActivated()
162162

163163
public static ValidationResult ValidateName(string name)
164164
{
165-
var instance = App.Current.Services.GetService<IPConfigListViewModel>();
166-
bool isValid = instance?.IPConfigList.Count(x => x.Name == name) <= 1;
165+
var instance = App.Current.Services.GetRequiredService<IPConfigListViewModel>();
166+
bool isValid = instance.IPConfigList.Count(x => x.Name == name) <= 1;
167167

168168
if (isValid)
169169
{

IPConfig/Views/IPConfigDetailView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public IPConfigDetailView()
2525
return;
2626
}
2727

28-
DataContext = App.Current.Services.GetService<IPConfigDetailViewModel>();
28+
DataContext = App.Current.Services.GetRequiredService<IPConfigDetailViewModel>();
2929

3030
WeakReferenceMessenger.Default.Register<KeyPressMessage>(this,
3131
(r, m) => {

IPConfig/Views/IPConfigListView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public IPConfigListView()
3232
return;
3333
}
3434

35-
DataContext = App.Current.Services.GetService<IPConfigListViewModel>();
35+
DataContext = App.Current.Services.GetRequiredService<IPConfigListViewModel>();
3636

3737
WeakReferenceMessenger.Default.Register<KeyPressMessage>(this,
3838
(r, m) => {

IPConfig/Views/IPv4ConfigView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public IPv4ConfigView()
2828
return;
2929
}
3030

31-
DataContext = App.Current.Services.GetService<IPConfigDetailViewModel>();
31+
DataContext = App.Current.Services.GetRequiredService<IPConfigDetailViewModel>();
3232

3333
_updateTargetTimer.Interval = TimeSpan.FromMicroseconds(100);
3434
_updateTargetTimer.Tick += DispatcherTimer_Tick;

IPConfig/Views/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public MainWindow()
4545
return;
4646
}
4747

48-
DataContext = App.Current.Services.GetService<MainViewModel>();
48+
DataContext = App.Current.Services.GetRequiredService<MainViewModel>();
4949

5050
LangSource.Instance.LanguageChanged += (s, e) => UpdateTitle();
5151
}

IPConfig/Views/NicConfigDetailView.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public NicConfigDetailView()
3434
return;
3535
}
3636

37-
DataContext = App.Current.Services.GetService<NicConfigDetailViewModel>();
37+
DataContext = App.Current.Services.GetRequiredService<NicConfigDetailViewModel>();
3838

3939
App.Current.ThemeChanging += (s, e) => _scrollViewerVOffset = scrollViewer.VerticalOffset;
4040
App.Current.ThemeChanged += (s, e) => scrollViewer.ScrollToVerticalOffset(_scrollViewerVOffset);

0 commit comments

Comments
 (0)