* 尝试解析服务 * * 如果服务未注册,返回null而不是抛出异常。 * * @param identifier - 服务标识符(构造函数或 Symbol) * @returns 服务实例或null * * @example * ```typescript * const timer = container.tryResolve(TimerManager); * if (timer) { * timer.schedule(...); * } * ```
(identifier: ServiceIdentifier<T>)
| 333 | * ``` |
| 334 | */ |
| 335 | public tryResolve<T extends IService>(identifier: ServiceIdentifier<T>): T | null { |
| 336 | try { |
| 337 | return this.resolve(identifier); |
| 338 | } catch { |
| 339 | return null; |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | /** |
| 344 | * 检查服务是否已注册 |
no test coverage detected