Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

when to create a method for a service?

$
0
0

Let's say I have a service called BookService, and I have method called GetAllBooks, GetBookById, and so on. Now I want to get all books that are recently modified, so do I need another method? or should I useGetAllBooks().Where(....)?

And in the code below, is there a difference between GetBooksByAuthorA and GetBooksByAuthorB?

public List<Book> GetAllBooks()
{
   return _context.Books.ToList();
}

public List<Book> GetBooksByAuthorA(string author)
{
   return _context.Books.Where(a => a.Author == author);
}

public List<Book> GetBooksByAuthorB(string author)
{
   return GetAllBooks().Where(a => a.Author == author);
}

PS: The code above is not tested and I only write it as an example of what point I'm trying to tell.


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>