Service Class with Multiple Repositories

253 Views Asked by At
class AccountClosureService(
    private val accountClosureRepository: AccountClosureRepository,
    private val userApplicationRepository: UserApplicationRepository,
){ 
// CRUD METHODS 
}

interface AccountClosureRepository{}

@Component
private class AccountClosureRepositoryImpl(): AccountClosureRepository
{}


interface UserApplicationRepository{}

@Component
private class UserApplicationRepositoryImpl():UserApplicationRepository
{}

I doesn't look fine to inject UserApplicationRepository in AccountClosureService as both Entities is different.

Not sure if we have a better way to implement above Class Design.

Checked RepositoryDesignPattern but no solution found for this case.

Any suggestions would be appreciated !!

1

There are 1 best solutions below

0
StepUp On

It looks like you have services which are responsible for business logic. If it is true and you use traditional layered architecture, then it is fine to inject various repositories in one service. A service can have any number of repositories, you don’t have to wrap each one in its own service. Some tutorials show only one service per entity because they want to show only framework features.