Re: Re: When using asp.net MVC...
2009-06-01 04:41:17 GMT
For command, the main reasons to use services are validation and backend systems.
As for query, backend system is still often a reason I need services.
The problem I have in my project is that most of the entity properties (e.g. Subscription) comes from backend services like billing-engine or TML rather than database. Only minimal subset of information is stored in database, but to get a complete state of the domain entity, simple repository lookup is not sufficient.
We put it behind a service that calls repository as well as remote call to billing engine and TML to populate the rest of subscription detail, but that opens up another can of worm:
1. It doesnt feel right to have the repository to load/persist only half of the entity state, leaving the other half unpopulated which clearly breaks object invariant.
2. No one ever says that repository has to be for database only. Why do we need Service to access remote backend? Repository is a layer that handles entity's states and lifecycle. Any thought about whether I should encapsulate lots of remote infrastructure behind repository (instead of services in application layer?).
3. Loading all entities information from all backend systems is not efficient. 99% of the time we don't need customer's address. Neither do we need how many accounts/susbcriptions they have, what plan they're on, or even if he's still active or not. We need some kind of lazy load mechanism really, but instead what we have is bunch of Service overload like:
getCustomerWithFullDetail()
getCustomerAndAllActiveSusbcrtipionWithoutAddressInfo()
getCustomerWithBlaBlaAndBla()
Thoughts?
Hi Jeff
Thanks very much for your reply. Are you saying you'd do things differently if the operation was a command?
Does anyone else have any thoughts on this? Jeff's the only person who's replied.
Gareth2009/5/30 Jeff Gillin <jeffro3377 <at> yahoo.com>I would say that for this particular concern you are showing, you don't need a service layer because you are just getting an item to display. When thinking in terms of command query separation, this is just a query and is perfectly OK to retrieve from your controller or presenter.
--- In domaindrivendesign <at> yahoogroups.com, Gareth Down <g <at> ...> wrote:
>
> Hi
>
> I am using ASP.NET MVC for a products I'm working on. I was just wondering
> what the DDD community thought about where the kind of "entry point" code
> should go, i.e. the code that accesses the repositories and actually brings
> everything together.
>
> Quite a few people say that you shouldn't really have very much in your
> controllers at all and they should really just field requests to a so called
> 'service' layer, for example:
>
> http://stackoverflow.com/questions/338816/should-controllers-in-an-asp-net-mvc-web-app-call-repositories-services-or-both
>
> I've started working for a new company and taken on a project where the
> previous developer has a 'service' for each of the entities, eg if there was
> a Product object there would be a ProductService with a few methods like
> GetProduct(int id) etc and basically whenever there's a call to a
> controller, it gets fielded to a service in the same way the person has
> suggested in that stackoverflow answer.
>
> The problem is I think these people are using the word service in a
> different way to the way DDD people talk about services. I think they're
> using the term in the way DDD people talk about repositories. For example
> the product I've inherited there are methods similar to
> GetAllVisibleProducts(), GetAllProducts(), DeleteProduct(id) etc, etc. I
> would say these were repository operations personally.
>
> Eric Evans says, as I'm sure you're all aware "A service tends to be named
> for an activity, rather than an entity - a verb rather than a noun".
>
> Therefore this approach seems wrong to me.
>
> Personally I can't see the problem of having the controller interact with
> the model directly.
>
> For example, I have this method: (I've stripped out a extra code that checks
> for a null entry etc and a security check etc, but you get the idea)
>
> public ActionResult EditEntry(int id, int subscriptionId)
> {
> var subscription =
> subscriptionRepository.FindSubscription(subscriptionId);
> var entry = subscription.Entries.FirstOrDefault(x => x.Id == id);
> return View(ViewModelOf(entry));
> }
>
> Now I can't see what is wrong with that? The user makes a request to edit a
> subscription entry, the controller asks the repository for the subscription,
> finds the entry and returns the View to the user.
>
> Why should I put a service there, aren't I just adding an extra layer for no
> reason? One reason people cite is code re-use, e.g. if you want to use the
> same code and put a different user interface there. But what if I know
> that's never going to happen? I know this app will never have a windows
> forms interface for example.
>
> Another example I've got is this: (note the ActiveUser property calls a user
> repository)
>
> public ActionResult Index()
> {
> return View(ActiveUser.Subscriptions);
> }
>
> That's really simple, is there any reason to add a whole other layer which
> does the same thing? To me it would mean more code to write more
> dependencies to hook up and more stuff to test.
>
> I'd really like to know if anyone has any thoughts about this or can point
> out anything I'm missing or not thinking of.
>
> Any responses would be much appreciated.
>
> Thanks
>
> Gareth
>
__._,_.___Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe
__,_._,___
RSS Feed