Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

无法在ICommand使用依赖注入服务 #732

Closed
loveyeguo opened this issue Jun 4, 2024 · 2 comments
Closed

无法在ICommand使用依赖注入服务 #732

loveyeguo opened this issue Jun 4, 2024 · 2 comments
Labels

Comments

@loveyeguo
Copy link

在net7中,我在ConfigureServices中注册了服务:
services.AddSingleton<IService, MyService>();
然后使用服务:
`public class MyCommand : ICommand
{
private readonly IService _service;

public MyCommand(IService service)
{
    _service = service;
}

public async Task ExecuteAsync(IAppSession session, StringPackageInfo package)
{
    // 在这里可以使用 _service 执行相关操作
}

}`

但是IService 实例化失败了,显示无法找到。 但是我如果重新定义一个普通的类,在构造函数里面进行IService 注入是可以的,这是什么原因?

@kerryjiang
Copy link
Owner

能写个测试用例重现这个问题吗?

@kerryjiang
Copy link
Owner

I just added a new unit test for this feature:
1f17983

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants