static ITest i { get; set; }
没给他赋值呀 
static void Main(string[] args)
        {
            i=new Test();
            i.SayHi("GT");//这里的i总是Null啊
            Console.ReadKey();
        }

解决方案 »

  1.   

    没有实例化,当然为空
     Test i = new Test();
                i.SayHi("GT");
                Console.ReadKey();
      

  2.   


    那为啥这个好用呢?疑惑啊,我也记得要new一个实现它的类啊    public class RolesServiceImp:IRolesService
        {
            [Inject]
            public IUnitOfWork UnitOfWork { get; set; }        [Inject]
            public IRolesRepository RolesRepository { get; set; }        [Inject]
            public IUserProfileRepository UserProfileRepository { get; set; }        [Inject]
            public IPermissionsRepository PermissionsRepository { get; set; }
            public IEnumerable<webpages_Roles> GetRolesList()
            {
                var query = RolesRepository.GetAll(); //这两个方法都用到了接口呢,也没new
                return query;
            }        public IEnumerable<webpages_Roles> Query(Expression<Func<webpages_Roles, bool>> where)
            {
                return RolesRepository.GetMany(where);//这两个方法都用到了接口呢,也没new        }
      

  3.   

    [Inject] 用到了这个,可能有用到返射,你看不到吧实例  public IRolesRepository RolesRepository { get; set; } 这个在其他地方有被赋值
      

  4.   

    依赖注入没找到这个的Bind,奇怪了,没发现原因。换了个地方声明莫名其妙的好了。