diff --git a/GFramework.Core/extensions/ContextAwareExtensions.cs b/GFramework.Core/extensions/ContextAwareExtensions.cs index d21a11a..50785e7 100644 --- a/GFramework.Core/extensions/ContextAwareExtensions.cs +++ b/GFramework.Core/extensions/ContextAwareExtensions.cs @@ -14,6 +14,20 @@ namespace GFramework.Core.extensions; /// public static class ContextAwareExtensions { + /// + /// 从上下文感知对象中获取指定类型的服务 + /// + /// 要获取的服务类型 + /// 实现 IContextAware 接口的上下文感知对象 + /// 指定类型的服务实例,如果未找到则返回 null + /// 当 contextAware 参数为 null 时抛出 + public static TService? GetService(this IContextAware contextAware) where TService : class + { + ArgumentNullException.ThrowIfNull(contextAware); + var context = contextAware.GetContext(); + return context.GetService(); + } + /// /// 获取架构上下文中的指定系统 /// @@ -28,6 +42,7 @@ public static class ContextAwareExtensions return context.GetSystem(); } + /// /// 获取架构上下文中的指定模型 ///