我正尝试在C#Web API中创建一个休息服务。C#Web API中的依赖注入
目前我没有考虑任何DB决策,因此我添加了一个模拟类库。
我正在创建一个模型接口并在模拟类库中实现模型。
public interface IUser
{
int userId { get; set; }
string firstName { get; set; }
string lastName { get; set; }
string email { get; set; }
List<IUser> getAllUsers();
IUser getUser(int ID);
bool updateUser(IUser user);
bool deleteUser(int ID);
}
,并在模拟类库
public class User : IUser
{
public string email { get; set; }
public string firstName { get; set; }
public string lastName { get; set; }
public int userId { get; set; }
public bool deleteUser(int ID)
{
throw new NotImplementedException();
}
public List<IUser> getAllUsers()
{
throw new NotImplementedException();
}
public IUser getUser(int ID)
{
throw new NotImplementedException();
}
public bool updateUser(IUser user)
{
throw new NotImplementedException();
}
}
实现这个现在模拟库引用的服务应用程序实现的接口。
现在我需要从服务应用程序中的控制器类调用模拟实现。
如何在不创建循环依赖的情况下执行此操作。我做了一些研究,并提出了一个解决方案,即DI是要走的路。
有人可以帮我实现这与代码示例?
非常感谢。
参见http://stackoverflow.com/q/12977743/126014 –