Skip to content

Commit f5f0986

Browse files
committed
remove some usage of Ioc.GetRequiredService when injection is possible.
1 parent ad63b0e commit f5f0986

File tree

5 files changed

+18
-23
lines changed

5 files changed

+18
-23
lines changed

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Linq;
6+
using Flow.Launcher.Infrastructure.UserSettings;
67

78
namespace Flow.Launcher.Infrastructure
89
{
@@ -14,15 +15,11 @@ public class StringMatcher
1415

1516
private readonly IAlphabet _alphabet;
1617

17-
public StringMatcher()
18-
{
19-
_alphabet = Ioc.Default.GetRequiredService<IAlphabet>();
20-
}
21-
2218
// This is a workaround to allow unit tests to set the instance
23-
public StringMatcher(IAlphabet alphabet)
19+
public StringMatcher(IAlphabet alphabet, Settings settings)
2420
{
2521
_alphabet = alphabet;
22+
UserSettingSearchPrecision = settings.QuerySearchPrecision;
2623
}
2724

2825
public static MatchResult FuzzySearch(string query, string stringToCompare)

Flow.Launcher/App.xaml.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,6 @@ await Stopwatch.NormalAsync("|App.OnStartup|Startup cost", async () =>
9191

9292
AbstractPluginEnvironment.PreStartPluginExecutablePathUpdate(_settings);
9393

94-
Ioc.Default.GetRequiredService<StringMatcher>().UserSettingSearchPrecision = _settings.QuerySearchPrecision;
95-
9694
// TODO: Clean InternationalizationManager.Instance and InternationalizationManager.Instance.GetTranslation in future
9795
InternationalizationManager.Instance.ChangeLanguage(_settings.Language);
9896

Flow.Launcher/PublicAPIInstance.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ public void SavePluginSettings()
247247
public void OpenDirectory(string DirectoryPath, string FileNameOrFilePath = null)
248248
{
249249
using var explorer = new Process();
250-
var explorerInfo = _settingsVM.Settings.CustomExplorer;
250+
var explorerInfo = _settingsVM._settings.CustomExplorer;
251251

252252
explorer.StartInfo = new ProcessStartInfo
253253
{
@@ -268,7 +268,7 @@ private void OpenUri(Uri uri, bool? inPrivate = null)
268268
{
269269
if (uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps)
270270
{
271-
var browserInfo = _settingsVM.Settings.CustomBrowser;
271+
var browserInfo = _settingsVM._settings.CustomBrowser;
272272

273273
var path = browserInfo.Path == "*" ? "" : browserInfo.Path;
274274

Flow.Launcher/SettingWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public partial class SettingWindow
2727
public SettingWindow()
2828
{
2929
var viewModel = Ioc.Default.GetRequiredService<SettingWindowViewModel>();
30-
_settings = viewModel.Settings;
30+
_settings = Ioc.Default.GetRequiredService<Settings>();
3131
DataContext = viewModel;
3232
_viewModel = viewModel;
3333
_updater = Ioc.Default.GetRequiredService<Updater>();

Flow.Launcher/ViewModel/SettingWindowViewModel.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,42 +6,42 @@ namespace Flow.Launcher.ViewModel;
66

77
public partial class SettingWindowViewModel : BaseModel
88
{
9-
public Settings Settings { get; init; }
9+
public readonly Settings _settings;
1010

11-
public SettingWindowViewModel()
11+
public SettingWindowViewModel(Settings settings)
1212
{
13-
Settings = Ioc.Default.GetRequiredService<Settings>();
13+
_settings = settings;
1414
}
1515

1616
/// <summary>
1717
/// Save Flow settings. Plugins settings are not included.
1818
/// </summary>
1919
public void Save()
2020
{
21-
Settings.Save();
21+
_settings.Save();
2222
}
2323

2424
public double SettingWindowWidth
2525
{
26-
get => Settings.SettingWindowWidth;
27-
set => Settings.SettingWindowWidth = value;
26+
get => _settings.SettingWindowWidth;
27+
set => _settings.SettingWindowWidth = value;
2828
}
2929

3030
public double SettingWindowHeight
3131
{
32-
get => Settings.SettingWindowHeight;
33-
set => Settings.SettingWindowHeight = value;
32+
get => _settings.SettingWindowHeight;
33+
set => _settings.SettingWindowHeight = value;
3434
}
3535

3636
public double? SettingWindowTop
3737
{
38-
get => Settings.SettingWindowTop;
39-
set => Settings.SettingWindowTop = value;
38+
get => _settings.SettingWindowTop;
39+
set => _settings.SettingWindowTop = value;
4040
}
4141

4242
public double? SettingWindowLeft
4343
{
44-
get => Settings.SettingWindowLeft;
45-
set => Settings.SettingWindowLeft = value;
44+
get => _settings.SettingWindowLeft;
45+
set => _settings.SettingWindowLeft = value;
4646
}
4747
}

0 commit comments

Comments
 (0)