无法解析类型 System.Collections.Generic.IAsyncEnumerable 的服务

Unable to resolve service for type System.Collections.Generic.IAsyncEnumerable

我有这个例外:

System.InvalidOperationException: 'Unable to resolve service for type 'System.Collections.Generic.IAsyncEnumerable`1[MyProject.Interfaces.IFooReader]' while attempting to activate 'MyProject.Services.FooService'.'

同时尝试用 var fooService = provider.GetRequiredService<IFooService>(); 解析 IFooService

这里是 FooService class:

public class FooService : IFooService
{
    private readonly IAsyncEnumerable<IFooReader> _foosReaders;

    public PriceService(IAsyncEnumerable<IFooReader> foosReaders)
    {
        this._foosReaders = foosReaders;            
    }
}

这是DI容器:

services.AddScoped<IFooReader, FooServiceA>(); 
services.AddScoped<IFooReader, FooServiceB>(); 
services.AddScoped<IFooReader, FooServiceC>(); 

services.AddScoped<IFooService, FooService>(); //assuming stateless

看起来原生.net-core DI容器不支持注入IAsyncEnumerable,有什么办法解决这个问题吗?

使用 IEnumerable 而不是 IAsncEnumerable 应该可以解决这个问题。

 public class FooService : IFooService

{
    private readonly IEnumerable<IFooReader> _foosReaders;

    public PriceService(IEnumerable<IFooReader> foosReaders)
    {
        this._foosReaders = foosReaders;            
    }
}