为什么我的接口在使用的时候总是Null static ITest i { get; set; }没给他赋值呀 static void Main(string[] args) { i=new Test(); i.SayHi("GT");//这里的i总是Null啊 Console.ReadKey(); } 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 没有实例化,当然为空 Test i = new Test(); i.SayHi("GT"); Console.ReadKey(); 那为啥这个好用呢?疑惑啊,我也记得要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 } [Inject] 用到了这个,可能有用到返射,你看不到吧实例 public IRolesRepository RolesRepository { get; set; } 这个在其他地方有被赋值 依赖注入没找到这个的Bind,奇怪了,没发现原因。换了个地方声明莫名其妙的好了。 按照C#入门经典的 windows编程中的一个例子做出错,求解答! 如何制作带app.confg的安装程序? 谁帮我通俗的讲讲abstract 和virtual修饰符的用法的区别 请问我定义了一个多个输出参数的存储过程,这样让他们输出为什么不正确? C# Winform 中如何实现右键更改属性? 大家讨论以一下C#的异常处理机制 listview 如何将图片和文字显示在同一列 ,但,不是第一列哦。 [求助]用C#调用SQLServer数据库的代码 为什么没有system.Management名称空间? WPF MVVM模式怎么给主窗体传值 急求 小时差的问题 C#实列化一个问题
Test i = new Test();
i.SayHi("GT");
Console.ReadKey();
那为啥这个好用呢?疑惑啊,我也记得要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 }