2
votes

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.

2
This question may be a better fit for 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
@EugenePodskal when referring other sites, it is often helpful to point that cross-posting is frowned upongnat
@Robertcode "a Product Services class which is used for all repository related actions".... what do you mean ? what does the service really do ?guillaume31
@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

2 Answers

2
votes

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.

0
votes

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