I have this class hierarchy:
public interface ISR { } public interface ICU { } public interface IFI { } public class CU : ICU { } public class SR : ISR { public SR(IFI fi) { FI = fi; } public IFI FI { get; set; } } public class FI : IFI { public FI(ISR sr, ICU cu) { SR = sr; CU = cu; } public ISR SR { get; set; } public ICU CU { get; set; } } public class Module : NinjectModule { public override void Load() { Bind<ISR>().To<SR>(); Bind<ICU>().To<CU>(); Bind<IFI>().To<FI>(); } } class Program { static void Main(string[] args) { var kernel = new StandardKernel(new Module()); var sr = kernel.Get<ISR>(); } }
When I run this code, I have an exception because I have a circular dependency. The SR class requires an IFI instance, which must be injected to complete, and the FI class requires an ISR instance for input.
Of course, using injection properties does not solve this problem.
I have a feature: I need to create an ISR first, and it is this instance that must be provided by FI. Thus, ISR and IFI must share the area.
How would you solve this with Ninject?
Mike source share