kirov-opensource / NAutowired

ASP.NET CORE Field Injection Implement
MIT License
77 stars 16 forks source link

解析IEnumerable<>服务集合报错 #21

Closed softworm closed 2 years ago

softworm commented 2 years ago
[Autowired]
IEnumerable<IFake> fakes;

报错 UnableResolveDependencyException: Unable to resolve dependency System.Collections.Generic.IEnumerable`1 看起来并不会尝试去根据元素类型解析服务集,而官方是支持注入服务集合的。 不知是否有支持计划?

服务注册:

public interface IFake
{
    void Echo();
}

[Service]
public class Foo : IFake
{
    public void Echo()
    {
        Console.WriteLine("this is Foo");
    }
}

[Service]
public class Bar : IFake
{
    public void Echo()
    {
        Console.WriteLine("this is Bar");
    }
}
FatTigerWang commented 2 years ago

目前不支持这种方式,但是你可以使用[Autowired(typeof(ImplementClass))]做到还原某一个具体的实例。 例如:

[Autowired(typeof(Foo))]
IFake fake;
softworm commented 2 years ago

创建了pullrequest,大佬看下有无问题:smile: