此代码不起作用。我基本上有一些超接口和子接口的实现。我希望超级接口返回所有实现,子接口只返回子实现。我不想明确地将子实现绑定到子接口和超级接口。我只想将它绑定到子接口并以某种方式将子绑定到超级。我正在尝试像这样设置它,但它不起作用:
class Program
{
static void Main(string[] args)
{
IKernel kernel = new StandardKernel();
kernel.Bind<ISuperInterface>().To<ISubInterface>(); // What can I do instead of this?
kernel.Bind<ISuperInterface>().To<SuperImplementation>();
kernel.Bind<ISubInterface>().To<SubImplementation>();
var subs = kernel.GetAll<ISubInterface>(); // I want this to return a SubImplementation
var supers = kernel.GetAll<ISuperInterface>(); // I want this to return a SuperImplementation and a SubImplementation
Console.WriteLine(subs.Count());
Console.WriteLine(supers.Count());
}
}
public class SubImplementation : ISubInterface
{
}
public class SuperImplementation : ISuperInterface
{
}
public interface ISuperInterface
{
}
public interface ISubInterface : ISuperInterface
{
}