Wednesday, 11 September 2013

Can I call a Method in an Api and have the same return?

Can I call a Method in an Api and have the same return?

I'm writing some ApiControllers, and due to abstraction boundaries, I
would like to write their actions in a distinct methods.
To do this I have created a class some methods. I'll take this one just as
an example:
public class MethodContainer<T> where T : model, new()
{
public List<T> MyList()
{
var getAll = repo.GetAll();
return getAll.ToList();
}
}
Then I have my ApiController, and I'm going to build it in this way:
public class MyApis<T> : ApiController
where T : model, new()
{
private MethodContainer<T> methcont;
public MyApis(MethodContainer<T> methcont)
{
this.methcont = methcont;
}
public List<T> ApiList()
{
var aList = methcont.MyList();
return aList;
}
}
Does the Api, built in that way, give me the same result as the Method I
built before?
That is does it return all the objects in the repository ToList()?
I'm quite sure I'm doing something wrong, but I have no experience enough
to get it.

No comments:

Post a Comment