2

I'm currently learning DDD and in my sample project, I have some questions with regards to architecture.

Right now, I have this:

WPF application (references service proxies which is in a separate assembly) -> Services (where the proxy came from) which references -> Domain layer (contains Domain objects and Repository interfaces) which then accesses -> DAL (which implements the repositories)

Questions:

  1. I know the answer depends on the situation but generally, is this architecture in the right path assuming all layers are needed?

  2. This is the first time I am using repository pattern, right now, my services has a constructor that accepts an IRepository. Where does the injection take place? Should the service layer contain a config file for what repository should be used? So this means, the service layer references both the repository interfaces in the domain layer and its implementation in the DAL?

  3. The WPF app references the service proxies so the constructor with a IRepository parameter doesn't get generated. Supposed I decided to use the services directly from WPF (no service proxies), how do I instantiate the service with an IRepository parameter from UI? I would need to add a reference to the DAL which contains the implementation of the repository? Is that OK or correct?

  4. Also, this design also means that the DAL should know about the IRepository interface (because they will implement the interface) as well as the Service Layer who will use the repository implementation. But my repository interfaces are in the domain layer; the DAL would need to reference the domain layer to get those interfaces which I think is wrong since I'm referenceing upstream. How do I do this?

g_b
  • 11,728
  • 9
  • 43
  • 80

1 Answers1

1

I know the answer depends on the situation but generally, is this architecture in the right path assuming all layers are needed?

Looks pretty standard to me. Just so you know, layering your architecture adds complexity. Make sure that the application is big enough to take full advantage of the Multi-Layer architecture.

Also, if you are separating the layers by assembly, make sure that they are also logically separated. The point of separating assemblies (inconjuction with logical separation) is that you can separate the development of one project without affecting or modifying the rest of the system.

Where does the injection take place?

In the highest layer, your composition root. In this case your WPF application.

More about composition root.

Should the service layer contain a config file for what repository should be used?

The decision of which concrete repository to use should be done in the composition root, placing the decision in the config file means extra flexibility, but it also means extra complexity. Is there a requirement that you need to do this?

So this means, the service layer references both the repository interfaces in the domain layer and its implementation in the DAL?

Only the repository interface in the Domain. Not the implementation. It doesn't need to. Don't do that.

how do I instantiate the service with an IRepository parameter from UI? I would need to add a reference to the DAL which contains the implementation of the repository? Is that OK or correct?

Yes. Your WPF is your composition root, it needs all the references so it can construct your architecture.

Also, this design also means that the DAL should know about the IRepository interface (because they will implement the interface) as well as the Service Layer who will use the repository implementation.

Why would the DAL reference the service layer? it doesn't need to. Don't do that.

But my repository interfaces are in the domain layer; the DAL would need to reference the domain layer to get those interfaces which I think is wrong since I'm referenceing upstream. How do I do this?

You are not referencing upstream, please refer to https://stackoverflow.com/a/24241373/1027250

Community
  • 1
  • 1
Yorro
  • 11,445
  • 4
  • 37
  • 47