日期:2014-05-17 浏览次数:20460 次
using System; using System.Collections.Generic; using System.Linq; using System.Text; using Ninject; namespace Test { class Program { static void Main(string[] args) { IKernel ninjectKernal = new StandardKernel(); ninjectKernal.Bind<ICalculateHelper>().To<CalculateHelper>(); ICalculateHelper ic = ninjectKernal.Get<ICalculateHelper>(); CalculateHelper ch = new CalculateHelper(ic); Console.WriteLine(ch.Add(1, 2).ToString()); Console.ReadKey(); } } public interface ICalculateHelper { decimal Add(decimal a, decimal b); decimal Sub(decimal a, decimal b); } public class CalculateHelper:ICalculateHelper { private ICalculateHelper ic; public CalculateHelper(ICalculateHelper icParam) { ic = icParam; } public decimal Add(decimal a, decimal b) { return b + a; } public decimal Sub(decimal a, decimal b) { return a - b; } } }
错误激活ICalculateHelper使用绑定从ICalculateHelper至CalculateHelperA循环依赖检测两个服务之间的构造函数。