From e2fef7110d6b2649fea0c8126e62c6220fa73ca7 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Fri, 30 Jan 2026 22:23:39 +0800 Subject: [PATCH] =?UTF-8?q?refactor(setting):=20=E6=9B=B4=E6=96=B0=20Setti?= =?UTF-8?q?ngsModel=20=E6=9E=84=E9=80=A0=E5=87=BD=E6=95=B0=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=E4=BE=9D=E8=B5=96=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 IDataLocationProvider 和 TRepository 从属性注入改为构造函数参数注入 - 移除字段初始化器中的空值赋值操作 - 简化依赖项的初始化流程,提高代码可读性 - 保持原有的数据仓库访问逻辑不变 - [release ci] --- GFramework.Game/setting/SettingsModel.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/GFramework.Game/setting/SettingsModel.cs b/GFramework.Game/setting/SettingsModel.cs index 6490f06..58312d5 100644 --- a/GFramework.Game/setting/SettingsModel.cs +++ b/GFramework.Game/setting/SettingsModel.cs @@ -13,7 +13,8 @@ namespace GFramework.Game.setting; /// - 管理 Settings Data 的生命周期(Load / Save / Reset / Migration) /// - 编排 Settings Applicator 的 Apply 行为 /// -public class SettingsModel : AbstractModel, ISettingsModel +public class SettingsModel(IDataLocationProvider locationProvider, TRepository repository) + : AbstractModel, ISettingsModel where TRepository : class, ISettingsDataRepository { private static readonly ILogger Log = @@ -28,9 +29,9 @@ public class SettingsModel : AbstractModel, ISettingsModel private readonly ConcurrentDictionary _data = new(); private readonly ConcurrentDictionary> _migrationCache = new(); private readonly ConcurrentDictionary<(Type type, int from), ISettingsMigration> _migrations = new(); - private IDataLocationProvider? _locationProvider; + private IDataLocationProvider? _locationProvider = locationProvider; - private ISettingsDataRepository? _repository; + private ISettingsDataRepository? _repository = repository; private ISettingsDataRepository DataRepository => _repository ?? throw new InvalidOperationException("ISettingsDataRepository not initialized.");