what’s the difference between service layer and domain model layer

The Domain Model contains information and functionality related to what it means to be a User. It should map conceptually onto something that exists physically in the real world or a clearly defined concept in the problem space. The Service contains information and functionality related to performing atomic units of work. It should map conceptually … Read more

Why use service layer?

Having the service layer be a wrapper around the DAO is a common anti-pattern. In the example you give it is certainly not very useful. Using a service layer means you get several benefits: you get to make a clear distinction between web type activity best done in the controller and generic business logic that … Read more

How to inject in @FacesValidator with @EJB, @PersistenceContext, @Inject, @Autowired

JSF 2.3+ If you’re already on JSF 2.3 or newer, and want to inject CDI-supported artifacts via e.g. @EJB, @PersistenceContext or @Inject, then simply add managed=true to the @FacesValidator annotation to make it CDI-managed. @FacesValidator(value=”emailExistValidator”, managed=true) JSF 2.2- If you’re not on JSF 2.3 or newer yet, then you basically need to make it a … Read more

ASP.NET MVC Business Logic in Domain Model vs Service Layer

First off, your Model folder in your Asp.Net MVC project should be used for ViewModels. These are the models that your Controllers send to your Views. They should be highly optimized for the View, meaning only the properties needed for the view, and nothing else. What you are taking about, Domain Models, are the same … Read more

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

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 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

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