I am trying to create a rest service in C# Web API.
At the moment I'm not considering any DB decisions, hence I'm adding a mock class library.
I'm creating a model interface and implementing the model in the mock class library.
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);
}
and implementing this in the mock class library
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();
}
}
Now the mock library references the service application to implement the interface.
Now I need to call the mock implementation from the controller class in the service application.
How do I do that without creating a cyclic dependency. I did some research and came up with a solution that DI is the way to go.
Can someone help me to implement this with code samples?
Many thanks.