0
이 코드는 작동하지 않습니다. 나는 기본적으로 슈퍼 인터페이스와 서브 인터페이스의 구현을 가지고있다. 수퍼 인터페이스가 모든 구현을 리턴하고 서브 인터페이스가 서브 구현만을 리턴하고 싶습니다. 서브 구현을 슈퍼 인터페이스와 슈퍼 인터페이스에 명시 적으로 바인드하고 싶지 않습니다. 하위 인터페이스에 바인딩하고 어떻게 든 서브를 슈퍼에 바인딩하고 싶습니다. 나는 이런 식으로 설정하기 위해 노력하고있어,하지만 작동하지 않습니다 :Ninject와 하위 인터페이스에 슈퍼 인터페이스 바인딩
는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
{
}