mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-03-25 21:34:28 +08:00
refactor(model): 优化模型架构上下文设置机制
- 移除通过反射调用SetArchitecture方法的方式 - 改为直接调用model.SetContext(Context)方法 - 将AbstractModel基类继承ContextAwareBase - 删除手动实现的SetContext和GetContext方法 - 简化模型注册流程,提高代码可读性
This commit is contained in:
parent
49ceb35156
commit
029f3a4652
@ -424,9 +424,7 @@ public abstract class Architecture(
|
|||||||
}
|
}
|
||||||
|
|
||||||
_logger.Debug($"Registering model: {typeof(TModel).Name}");
|
_logger.Debug($"Registering model: {typeof(TModel).Name}");
|
||||||
// 对于有 SetArchitecture 方法的模型,尝试调用该方法
|
model.SetContext(Context);
|
||||||
var setArchitectureMethod = typeof(TModel).GetMethod("SetArchitecture", [typeof(IArchitecture)]);
|
|
||||||
setArchitectureMethod?.Invoke(model, [this]);
|
|
||||||
Container.RegisterPlurality(model);
|
Container.RegisterPlurality(model);
|
||||||
|
|
||||||
if (!_mInitialized)
|
if (!_mInitialized)
|
||||||
|
|||||||
@ -1,19 +1,14 @@
|
|||||||
using GFramework.Core.Abstractions.architecture;
|
using GFramework.Core.Abstractions.enums;
|
||||||
using GFramework.Core.Abstractions.enums;
|
|
||||||
using GFramework.Core.Abstractions.model;
|
using GFramework.Core.Abstractions.model;
|
||||||
|
using GFramework.Core.rule;
|
||||||
|
|
||||||
namespace GFramework.Core.model;
|
namespace GFramework.Core.model;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 抽象模型基类,实现IModel接口,提供模型的基本架构支持
|
/// 抽象模型基类,实现IModel接口,提供模型的基本架构支持
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public abstract class AbstractModel : IModel
|
public abstract class AbstractModel : ContextAwareBase, IModel
|
||||||
{
|
{
|
||||||
/// <summary>
|
|
||||||
/// 模型所属的架构实例
|
|
||||||
/// </summary>
|
|
||||||
protected IArchitectureContext _context { get; private set; } = null!;
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 初始化模型,调用抽象方法OnInit执行具体初始化逻辑
|
/// 初始化模型,调用抽象方法OnInit执行具体初始化逻辑
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -22,16 +17,6 @@ public abstract class AbstractModel : IModel
|
|||||||
OnInit();
|
OnInit();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SetContext(IArchitectureContext context)
|
|
||||||
{
|
|
||||||
_context = context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public IArchitectureContext GetContext()
|
|
||||||
{
|
|
||||||
return _context;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 处理架构阶段事件的虚拟方法
|
/// 处理架构阶段事件的虚拟方法
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user