Skip to content

fix: 修复依赖注入配置问题 - 应用程序无法启动#33

Merged
ModerRAS merged 1 commit intomasterfrom
feature/gui-enhancement-new
Aug 25, 2025
Merged

fix: 修复依赖注入配置问题 - 应用程序无法启动#33
ModerRAS merged 1 commit intomasterfrom
feature/gui-enhancement-new

Conversation

@ModerRAS
Copy link
Copy Markdown
Contributor

Summary

  • 修复了 UnifiedEditorFactory 无法解析 ILogServiceIErrorHandlerService 的依赖注入问题
  • App.axaml.csConfigureServices 方法中添加了缺失的服务注册
  • 应用程序现在可以正常启动并显示 Avalonia UI 界面

Problem

应用程序启动时出现以下错误:

System.InvalidOperationException: Unable to resolve service for type 'BannerlordModEditor.UI.Services.ILogService' while attempting to activate 'BannerlordModEditor.UI.Factories.UnifiedEditorFactory'

Root Cause

UnifiedEditorFactory 类的构造函数需要以下依赖:

  • ILogService logService
  • IErrorHandlerService errorHandlerService

但在 App.axaml.csConfigureServices() 方法中,这两个服务没有被注册到依赖注入容器中。

Solution

App.axaml.cs 中添加了缺失的服务注册:

// 注册日志和错误处理服务
services.AddSingleton<ILogService, LogService>();
services.AddSingleton<IErrorHandlerService, ErrorHandlerService>();

Test plan

  • 应用程序构建成功
  • 所有单元测试通过 (185个测试)
  • 使用xvfb模拟图形界面验证应用程序正常启动
  • 添加依赖注入测试验证配置正确性
  • 确认编辑器工厂能够正确创建所有编辑器实例

🤖 Generated with Claude Code

- 在App.axaml.cs的ConfigureServices方法中添加ILogService和IErrorHandlerService注册
- 解决UnifiedEditorFactory无法解析依赖服务的启动错误
- 添加依赖注入测试以验证配置正确性
- 应用程序现在可以正常启动并显示Avalonia UI界面

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings August 25, 2025 11:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a dependency injection configuration issue that prevented the application from starting. The UnifiedEditorFactory was unable to resolve required dependencies (ILogService and IErrorHandlerService), causing startup failures.

  • Added missing service registrations for ILogService and IErrorHandlerService in the DI container
  • Created comprehensive tests to verify dependency injection configuration
  • Ensured all required services can be properly resolved by the service provider

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
BannerlordModEditor.UI/App.axaml.cs Added missing service registrations for log and error handling services
BannerlordModEditor.UI.Tests/DependencyInjection/DependencyInjectionTests.cs Added comprehensive test suite to verify dependency injection configuration

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@ModerRAS ModerRAS merged commit beb0b63 into master Aug 25, 2025
28 checks passed
@ModerRAS ModerRAS deleted the feature/gui-enhancement-new branch August 25, 2025 11:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants