danvega/spring-common-mistakes

Issue with item number 1 from video

Opened this issue · 0 comments

Hello Dan,

I am following your youtube series, and they are very cool.

If not anything else, just wanted to say thank you for the videos you are creating. they are clear, easy to follow, and very interesting.

I am having one particular issue and would like to talk to you.
This is related to your talk https://www.youtube.com/watch?v=PbkROQPTBao example 1.

  • What I am trying to achieve

I wish to use "Package by Feature" for my @configuration files.
Currently, I am using "Package by Layer".

  • This is the current code structure:

Package by layer:

├── com.app
    └── configuration
        ├── KafkaProducerConfiguration
        ├── MongoRepositoryConfiguration
        └── RestClientConfiguration
    └── controller
        ├── CompanyController
        ├── ProductController
        └── UserController
    └── model
        ├── Company
        ├── Product
        └── User
    └── repository
        ├── CompanyRepository
        ├── ProductRepository
        └── UserRepository
    └── service
        ├── CompanyService
        ├── ProductService
        └── UserService

The kafka producer is needed by the company service to send messages to other parts of the company
The rest client is needed by the user service and the product service to query some external information
The mongo repository is needed to configure all three classes in the repository layer.

  • What I tried:

Following this guide: https://medium.com/sahibinden-technology/package-by-layer-vs-package-by-feature-7e89cde2ae3a

I am refactoring to this:

├── com.app
    └── configuration
        ├── KafkaProducerConfiguration
        ├── MongoRepositoryConfiguration
        └── RestClientConfiguration
    └── company
        ├── Company
        ├── CompanyController
        ├── CompanyRepository
        └── CompanyService
    └── product
        ├── Product
        ├── ProductController
        ├── ProductRepository
        └── ProductService
    └── user
        ├── User
        ├── UserController
        ├── UserRepository
        └── UserService
  • Issue:

Unfortunately, I am facing difficulties in refactoring the configuration layer, and I would like to avoid a hybrid package by feature + package by layer.

  • Question:

How to refactor this configuration layer into the "Package by feature"?