mardi 17 décembre 2019

Achieving Hexagonal design pattern with maven multi module application

I am planning to migrate my maven based multi module java application to achieve the Hexagonal design pattern. Reference taken from https://blog.octo.com/en/hexagonal-architecture-three-principles-and-an-implementation-example/

Reason to consider hexagonal design pattern is

  • Domain should not be dependent on the application and infrastructure part
  • Domain will be driven by REST / HTTP request / File request etc
  • Domain will be connecting to different external stuffs like DB, File, Queue etc

Suppose this project has different modules

  • Domain
  • Infra
  • Application

My Questions are

1) I consider that Hexagon will be initiated from Application side then Application project has to be dependent on Infra project and Domain project both (means I have to provide dependencies of Infra & Domain in Application module)

Is it a correct way or I have interpreted it wrongly??

-

2) I want to make Domain and Infra projects are loosely coupled Hexagonal example -

Interface on domain side

package domain.manager.spi;

public interface FileRepository {
String findFileNameById(int id);
}

Implementation on infrastructure side

package infrastructure.repository.filesystem;

import domain.manager.spi.FileRepository;

public class FileQueueStorage implements FileRepository {

  @Override
  public String findFileNameById(int id) {
      String str = "From FileQueue Infra "+id;
      return str;
  }

}

And now I want to use this FileQueueStorage class functions in Domain project How to achieve this? Presently it is giving me cyclic dependency issue on maven side.

-

3) How to arrange such multi module project to avoid such cyclic dependencies provided that APPLICATION, DOMAIN, INFRASTRUCTURE should be different module

Awaiting your valuable feedback.

Aucun commentaire:

Enregistrer un commentaire