[DI] Refactor `Global` a bit
MODIFY
WalletWasabi.Gui/Global.cs
WalletWasabi.Gui/Global.cs
@@ -80,25 +80,20 @@ namespace WalletWasabi.Gui
public static JsonRpcServer RpcServer { get; private set; }
- public Global()
+ public Global(string dataDir, string torLogsFile, Config config, UiConfig uiConfig, WalletManager walletManager)
{
using (BenchmarkLogger.Measure())
{
StoppingCts = new CancellationTokenSource();
- DataDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Client"));
- TorLogsFile = Path.Combine(DataDir, "TorLogs.txt");
- Directory.CreateDirectory(DataDir);
+ DataDir = dataDir;
+ Config = config;
+ UiConfig = uiConfig;
+ TorLogsFile = torLogsFile;
Logger.InitializeDefaults(Path.Combine(DataDir, "Logs.txt"));
- UiConfig = new UiConfig(Path.Combine(DataDir, "UiConfig.json"));
- UiConfig.LoadOrCreateDefaultFile();
- Config = new Config(Path.Combine(DataDir, "Config.json"));
- Config.LoadOrCreateDefaultFile();
- Config.CorrectMixUntilAnonymitySet();
-
HostedServices = new HostedServices();
- WalletManager = new WalletManager(Network, new WalletDirectories(DataDir));
+ WalletManager = walletManager;
LegalDocuments = LegalDocuments.TryLoadAgreed(DataDir);

MODIFY
WalletWasabi.Gui/Program.cs
WalletWasabi.Gui/Program.cs
@@ -11,7 +11,9 @@ using System.Runtime.InteropServices;
using System.Threading.Tasks;
using WalletWasabi.Gui.CommandLine;
using WalletWasabi.Gui.ViewModels;
+using WalletWasabi.Helpers;
using WalletWasabi.Logging;
+using WalletWasabi.Wallets;
namespace WalletWasabi.Gui
{
@@ -26,7 +28,7 @@ namespace WalletWasabi.Gui
bool runGui = false;
try
{
- Global = new Global();
+ Global = CreateGlobal();
Locator.CurrentMutable.RegisterConstant(Global);
@@ -64,6 +66,22 @@ namespace WalletWasabi.Gui
}
}
+ private static Global CreateGlobal()
+ {
+ string dataDir = EnvironmentHelpers.GetDataDir(Path.Combine("WalletWasabi", "Client"));
+ Directory.CreateDirectory(dataDir);
+ string torLogsFile = Path.Combine(dataDir, "TorLogs.txt");
+
+ var uiConfig = new UiConfig(Path.Combine(dataDir, "UiConfig.json"));
+ uiConfig.LoadOrCreateDefaultFile();
+ var config = new Config(Path.Combine(dataDir, "Config.json"));
+ config.LoadOrCreateDefaultFile();
+ config.CorrectMixUntilAnonymitySet();
+ var walletManager = new WalletManager(config.Network, new WalletDirectories(dataDir));
+
+ return new Global(dataDir, torLogsFile, config, uiConfig, walletManager);
+ }
+
private static bool ShouldRunGui(string[] args)
{
var daemon = new Daemon(Global);

[DI] Refactor `Global` a bit