I have a little experience working with Dependency Injection using Xamarin.Forms, but not in WebApi, What I want is send data through my Interface and execute inside of my Class which is implementing that Interface, there's what I have :
public interface IRepository
{
IHttpActionResult SendContext(user user);
IHttpActionResult GetContextData(int id);
}
public class ContextGoneBase : ApiController,IRepository
{
public IHttpActionResult GetContextData(int id)
{
try
{
using (var context = new GoneContext())
{
var result = context.user.Where(a => a.id_user == id).Select(w =>
new { w.user_name, w.cellphone_number, w.user_kind, w.CEP, w.area.area_name, w.district, w.city.city_name, w.city.state.state_name });
var list = result.ToList();
if (list != null)
{
return Ok(list);
}
else
{
return BadRequest();
}
}
}
catch (Exception)
{
return BadRequest();
}
}
And Inside of my controller I was trying to do something like that:
[Route("86538505")]
public IHttpActionResult GetData(int id, IRepository repo)
{
this._repo = repo;
var result = _repo.GetContextData(id);
return result;
}
But, it fails! Thanks!