Home  /  Questions  /  Question



50   50
Dec 31, 2010


DoFactory Architecture Design

Hi,

I just have a question on the architecture. I always thought that the service must call the repository. In the solution the have ActionService and a repository. Lets say I want to get all the customers then in my controller I would call the repository's GetCustomers method. This will then call ActionService's GetCustomer's method. And then lastly another GetCustomers method is called in the customer data access object. Is this right?  Is it best practices to do it this way, or is your service implementation something different to my understanding of a service?  How I understand it is as follows.  A service like CustomerService has a Save method.  In this method logic is applied, when everything is a success then the repository's Save method is called.

Any comments on the way that they implemented things in the Patterns in Action?



588   99.9
Jan 01, 2011
Brendan,

I can't really answer for the DoFactory guys, but I do know what you are talking about in this case.  And I assume you are referring to the MVC implementation.  This implementation is done this way, as far as I can see, to allow the controllers to be testable.

Since the application gets a reference to the WCF service, they could have made a reference to the WCF service proxy directly in the controllers, but then you wouldn't have an easy way of testing them. 

By wrapping the WCF service inside local repositories, you can test your controllers without affecting the rest of the application.

In my applications, when I use the PIA pattern, I take it a step farther and decorate the local models with DataAnnotations for form validation.

I've built this functionality into my code generator so it builds all this stuff for you.

I know it seems like a lot of stuff that may be redundant, but the way this application is separated, it kinda needs to be this way, or something close to it in order to provide maximum flexibility and testability.

And if you were to time it, round trip, page requests take only milliseconds.

This isn't the only way to do things, but it is one way.  It's really up to you to see if it fits your needs.

I hope this answered your question.

King Wilder
 1 comment
 
Hi King Wilder, Thanks for your answer. I think I have a confusion as to a service layer and a service. The action service, is this the gateway into the methods exposed by the service? Yes I actually use Fluent Validation to handle my input validations. Just a quick question, where would validation go into seeing that the business objects are exposed by the service to more than 1 client. Also, where would business rules go? I have read that I need a service that exposes the methods in the repository. Why do you think this was not used here? Then this service handles all application logic. Was it done this way or am I just not seeing it? Brendan --- Brendan Vogt  Jan 02, 2011