Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

About multiple usecases #201

Open
YJack0000 opened this issue Nov 4, 2023 · 3 comments
Open

About multiple usecases #201

YJack0000 opened this issue Nov 4, 2023 · 3 comments

Comments

@YJack0000
Copy link

YJack0000 commented Nov 4, 2023

Hello, I am a new to golang and clean arch!
And I am curious about the design of the usecase directory

When I start a program, the repo and the webapi part are just directly injected into the usecase and create a translationUseCase. Does it means that the translation usecase just representing the all usecases? But what if I want to add new usecases?

translationUseCase := usecase.New(
    repo.New(pg),
    webapi.New(),
)

If I trying to use more usecase.New in my project like

AUseCase := usecase.NewA(
    repo.New(pg),
    webapi.New(),
)
BUseCase := usecase.NewB(
    repo.New(pg),
)

And I have to append a lot of params to v1.NewRouter(handler, l, testUseCase)
For example:

v1.NewRouter(handler, l, AUseCase, BUseCase)

If I do this, the NewRouter params will just grow as far as the project grow. It seem not like a good way to solve that.

Does anyone have idea about it?

@melazyk
Copy link

melazyk commented Nov 12, 2023

I'm trying to use this template, but I'm stuck with the same damn problem. Can't seem to find a way out of this mess.

@ysomad
Copy link

ysomad commented Dec 2, 2023

Don't use the template, make your own code architecture for a project you building.

@SebUndefined
Copy link

You could create a "Deps" structure. Initialize it with a constructor and pass this structure to the router.

´´´
type Deps struct {
UseCaseA *usecases.UseCaseA
...
}
´´´

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants