Separating the service layer from the validation layer

Short answer: You are validating the wrong thing. Very long answer: You are trying to validate a PurchaseOrder but that is an implementation detail. Instead what you should validate is the operation itself, in this case the partNumber and supplierName parameters. Validating those two parameters by themselves would be awkward, but this is caused by … Read more

Should the repository layer return data-transfer-objects (DTO)?

Short answer: No. Long answer: repository is responsible for turning persisted data back to entities (models) and vice versa. Model is a business Model representing a business entity. DTO on the other hand – while looks like Model – is concerned with transfer of the object between various environment and in essence is a transient … Read more

Are Doctrine2 repositories a good place to save my entities?

Yes, repositories are generally used for queries only. Here is how I do it. The service layer manages the persistence. The controller layer knows of the service layer, but knows nothing of how the model objects are persisted nor where do they come from. For what the controller layer cares is asking the service layer … Read more

Service Layer vs Business Layer in architecting web applications?

It is all about decoupling your app into self contained pieces, each one defined by the requirement to do one job really well. This allows you to apply specialised design patterns and best practices to each component. For example, the business layer’s job is to implement the business logic. Full stop. Exposing an API designed … Read more

Should a service layer return view models for an MVC application?

Generally, no. View models are intended to provide information to and from views and should be specific to the application, as opposed to the general domain. Controllers should orchestrate interaction with repositories, services (I am making some assumptions of the definition of service here), etc and handle building and validating view models, and also contain … Read more

Fat model / thin controller vs. Service layer [closed]

All of this depends on the intention and requirements of your application. That said, here’s my suggestion for “mid scale” (not a local restaurant, and not Twitter/Facebook) web applications. Lean Domain Modeling Dry POCO style objects, preferably ignorant to the MVC architecture of your web application to remain as loosely coupled from your particular implementation … Read more

Difference between Repository and Service Layer?

Repository Layer gives you additional level of abstraction over data access. Instead of writing var context = new DatabaseContext(); return CreateObjectQuery<Type>().Where(t => t.ID == param).First(); to get a single item from database, you use repository interface public interface IRepository<T> { IQueryable<T> List(); bool Create(T item); bool Delete(int id); T Get(int id); bool SaveChanges(); } and … Read more