service-layer

ASP.NET MVC with service layer and repository layer, where should the interfaces be defined?

家住魔仙堡 提交于 2019-11-29 18:53:30
I am in the process of determining a fairly simple layered architecture for a .NET MVC application that has a repository layer and a service layer. I have found some fairly clear and simple examples, notably www.asp.net , and some questions and answers here, but I am looking for something that is a little simpler, suitable for small applications, but that uses different projects, to get the idea across. The example I linked to above has the repository and service as classes in the Models namespace. That just isn't enough of a clear separation for me to be able to illustrate it properly. I have

Doctrine2 Best Practice, Should Entities use Services?

爱⌒轻易说出口 提交于 2019-11-29 16:19:48
问题 I asked a similar question a while back: Using the Data Mapper Pattern, Should the Entities (Domain Objects) know about the Mapper? However, it was generic and I'm really interested in how to accomplish a few things with Doctrine2 specifically . Here's a simple example model: Each Thing can have a Vote from a User , a User may cast more than one Vote but only the last Vote counts. Because other data ( Msssage , etc) is related to the Vote , when the second Vote is placed the original Vote can

How to combine JSR-303 and Spring Validator class in a service layer?

≯℡__Kan透↙ 提交于 2019-11-29 02:31:45
I have some model class public class Account { @Email private String email; @NotNull private String rule; } and spring-validator public class AccountValidator implements Validator { @Override public boolean supports(Class aClass) { return Account.class.equals(aClass); } @Override public void validate(Object obj, Errors errors) { Account account = (Account) obj; ValidationUtils.rejectIfEmpty(errors, "email", "email.required"); ValidationUtils.rejectIfEmpty(errors, "rule", "rule.required"); complexValidateRule(account.getRule(), errors); } private void complexValidateRule(String rule, Errors

Designing service layer classes in PHP

心已入冬 提交于 2019-11-29 00:40:01
问题 I was recently introduced to service layers by Jani Hartikainen in a discussion about how to best handle form data in a MVC app. After doing some reading I can really see the benefits of this approach. My question is this: How should services classes be structured? First, is user_service() an appropriate class name for my user() model or is there another standard? Since the methods in my service will only be doing one task, is it correct to think that these can always be a static function ? A

Checked vs. Unchecked Exceptions in Service Layer

只谈情不闲聊 提交于 2019-11-28 17:37:30
I work on a project with a legacy service layer that returns null in many places if a requested record does not exist, or cannot be accessed due to the caller not being authorized. I am talking about specific records requested by ID. For instance, something like: UserService.get(userId); I have recently pushed to have this API changed, or supplemented with a new API that throws exceptions instead. The debate over checked vs unchecked exceptions has ensued. Taking a note from the designers of JPA/Hibernate et all., I have suggested that unchecked exceptions may be most appropriate. My argument

Separating the service layer from the validation layer

℡╲_俬逩灬. 提交于 2019-11-28 15:11:00
I currently have a service layer based on the article Validating with a service layer from the ASP.NET site. According to this answer, this is a bad approach because the service logic is mixed with the validation logic which violates the single responsibility principle. I really like the alternative that is supplied but during re-factoring of my code I have come across a problem that I am unable to solve. Consider the following service interface: interface IPurchaseOrderService { void CreatePurchaseOrder(string partNumber, string supplierName); } with the following concrete implementation

How should EntityManager be used in a nicely decoupled service layer and data access layer?

只愿长相守 提交于 2019-11-27 21:33:23
Somewhat related to my other question Should raw Hibernate annotated POJO's be returned from the Data Access Layer, or Interfaces instead? , I am experienced in creation of nicely decoupled layers, but not using Hibernate or J2EE/JPA. I have been looking at documentation and tutorials, and am puzzled about how to use the EntityManger in an elegant way, as it seems it is responsible for both transactions (which I want to do at my service layer) and persistance methods (which I want to keep in the data access layer). Should I create it at the service layer and inject it into the data access

The Purpose of a Service Layer and ASP.NET MVC 2

风流意气都作罢 提交于 2019-11-27 17:52:37
In an effort to understand MVC 2 and attempt to get my company to adopt it as a viable platform for future development, I have been doing a lot of reading lately. Having worked with ASP.NET pretty exclusively for the past few years, I had some catching up to do. Currently, I understand the repository pattern, models, controllers, data annotations, etc. But there is one thing that is keeping me from completely understanding enough to start work on a reference application. The first is the Service Layer Pattern. I have read many blog posts and questions here on Stack Overflow, but I still don't

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

ε祈祈猫儿з 提交于 2019-11-27 17:34:54
Say you have an ASP.NET MVC project and are using a service layer, such as in this contact manager tutorial on the asp.net site: http://www.asp.net/mvc/tutorials/iteration-4-make-the-application-loosely-coupled-cs If you have viewmodels for your views, is the service layer the appropriate place to provide each viewmodel? For instance, in the service layer code sample there is a method public IEnumerable<Contact> ListContacts() { return _repository.ListContacts(); } If instead you wanted a IEnumerable, should it go in the service layer, or is there somewhere else that is the "correct" place?

Checked vs. Unchecked Exceptions in Service Layer

牧云@^-^@ 提交于 2019-11-27 10:36:51
问题 I work on a project with a legacy service layer that returns null in many places if a requested record does not exist, or cannot be accessed due to the caller not being authorized. I am talking about specific records requested by ID. For instance, something like: UserService.get(userId); I have recently pushed to have this API changed, or supplemented with a new API that throws exceptions instead. The debate over checked vs unchecked exceptions has ensued. Taking a note from the designers of