2

I have a N-Layered Winforms application with 4 layers as follows:

Presentation Layer

Application Layer

Domain Layer

Infrastructure Layer

My Application Layer has a Product Services class which is used for all repository related actions for Products.

Does the interface file for the Product Services class belong in the Application Layer or Domain Layer? I ask because the interface file for my repositories is defined in the Domain Layer even though they are implemented in the Infrastructure Layer.

Thanks in advance.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
Robertcode
  • 911
  • 1
  • 13
  • 26
  • This question may be a better fit for http://programmers.stackexchange.com/. And as far as I understand each layer in ideal n-tier should know only about the one-level lower layer (UI->Application->Domain->Infra, but Application shouldn't know about Infra), so in your case it seems to be a violation of proper n-tier. – Eugene Podskal Feb 27 '16 at 15:27
  • @EugenePodskal when referring other sites, it is often helpful to point that [cross-posting is frowned upon](http://meta.stackexchange.com/tags/cross-posting/info) – gnat Feb 27 '16 at 19:29
  • @Robertcode "a Product Services class which is used for all *repository related* actions".... what do you mean ? what does the service really do ? – guillaume31 Feb 29 '16 at 10:54
  • @guillaume31 The Product Services class is in the Application Layer. It's purpose is to handle all CRUD operations for a Product. So all UI requests in the Presentation Layer to add, update, or delete a Product are passed to the Product Services class which in turn passes the request to Domain for validations then the ProductRepository. The repository return results are converted to DTOs by the Product Service and sent back to the UI for display. – Robertcode Mar 05 '16 at 06:42

2 Answers2

2

Service concept can belong to any layer. If you ask for application services, then these should live in the application layer.

In the other hand, if these services are the ones directly accessing the domain, then they're still domain. That is, I would expect to find both a service interface and one or more implementations in any project prefixed with Domain.

BTW, the project has nothing to do with software layers. It's just an organizational unit to group files by some criteria. The most important point is your flow should work with inversion of control in mind to glue layers.

Matías Fidemraizer
  • 63,804
  • 18
  • 124
  • 206
0

With DDD, is usually recommended to use Dependency Inversion (the D in SOLID), so the tree of dependencies should be

                      Domain Layer
                            |
                           / \ 
                          /   \
        Presentation Layer     Infrastructure Layer

So the Presentation and Infrastructure "layers" depend on your domain, and not the other way around (the generic version of this is also know as Hexagonal Architecture or Ports and Adapters)

And the Application Layer is indeed part of your domain, as it defines how use cases are supposed to work. I've never used (or seen) an application layer in an application, but what I've done is to put the Application Services in a different package inside the same artefact (the terminology here might be a bit different as I come from a Java background).

Augusto
  • 28,839
  • 5
  • 58
  • 88
  • 1
    I see Application Layers all the time. For instance [this](https://github.com/VaughnVernon/IDDD_Samples/tree/master/iddd_collaboration/src/main/java/com/saasovation/collaboration) sample by Vaughn Vernon has an `application` layer (with multiple packages under it) besides `domain`. Also see http://gorodinski.com/blog/2012/04/14/services-in-domain-driven-design-ddd/ – guillaume31 Feb 29 '16 at 11:04
  • The Application Layer does use the domain's Ubiquitous Language throughout its use cases, however to me it is technically not part of the Domain Layer. Application Layer can also do boilerplate things that are not related to the domain, such as verifying that `confirmPassword` is equal to `password`, checking max length of strings, etc. – guillaume31 Feb 29 '16 at 11:06