c# - Should the Repository pattern manipulate an object before passing it to the consumer/service layer? -


the current solution working structured single core layer connecting database whenever needs retrieve data.

i suggested few colleagues create dal layer , move of database logic it's own project , call

application.dataaccess 

this layer use entity framework , repository pattern abstraction between application.core , application.dataaccess (the repository implementation sit within application.dataaccess).

i plan to consume repository in service layer.

public class jobservice {    private ijobrepository _jobrepository;     public jobservice(ijobrepository repository)     {       _jobrepository = repository;    }     public ienumerable<job> getjobs()     {       list<jobs_alljobs> alljobs = _jobrepository.getalljobs();       list<job> result = new list<job>();        foreach(job in alljobs)        {         result.add(new jobs() { title = job.title, otherentity = "internal service"; });       }                  return result;   } } 

job repository:

public class jobrepository : irepository<jobs_alljobs> {      dbcontext _jobcontext;       public list<jobs_alljobs> getjobs()       {          return _jobcontext.jobs_alljobs.tolist();      } } 

this gets heated between us.

i believe jobrepository should return list of database entity jobs_alljobs rather manipulate database entity , construct new list of job (this should handled in service layer). colleagues believe manipulation should done @ repository level , jobrepository should pass list<job> or ienumerable<job> rather database entity.

from understanding repository pattern meant abstract away internal database implementation (entity framework/nhibernate/file system) , solely perform crud operation upon database (create, retrieve, update or delete) , jobservice should perform manipulation , construct new object , pass down consumer.

which way correct? , way follows repository pattern best?


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -