79833957

Date: 2025-11-30 14:30:52
Score: 0.5
Natty:
Report link

Sorry, forgot to add some details in the question:

  1. Yes, I do have repositories interacting with my DB
  2. I'm instanciating my Handlers, UseCases, Repositories and Orchestartors inside a Depency Injection Container

Ex of repository:


type CoreUserRepository struct {
    db *sqlx.DB
}

func NewCoreUserRepository(db *sqlx.DB) *CoreUserRepository {
    return &CoreUserRepository{db: db}
}

func (repo *CoreUserRepository) Exists(idTenant int64, idUser int64) *int64 {
    query := "SELECT id FROM core.users WHERE id_tenant=$1 AND id=$2;"

    var id int64
    err := repo.db.QueryRowx(query, idTenant, idUser).Scan(&id)
    if err != nil {
        log.Println("[CORE USERS - REPO] Could not find user: ", err)
        return nil
    }

    return &id
}

I'm also thinking in creating Request Containers Dependency Injection for my Unit of Work. Each request creates a new container that's injects the necessary repos, usecases AND the request context. I create the UW, pass it to the context and inject the context in the usecases and repositories. With this, I'd not have the problem of having a "global transaction" in my whole application when declaring a Unit Of Work. You think that's too much? Sorry, first time with an application of this size/complexity ;-;

Reasons:
  • Long answer (-1):
  • Has code block (-0.5):
  • Contains question mark (0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Alan Graton