Coder Social home page Coder Social logo

Comments (2)

hatajoe avatar hatajoe commented on August 11, 2024 1

@frederikhors I'm sorry for the late reply, and thank you for giving me a question.

Where do you think I should do something like below? In handler, usecase or repository?

First, I think the point is your application boundary.
Regarding a multi-tenancy application, the data referred by API are always bounded by specified tenant. Thus I think the handler has a responsibility to solve the boundary of the application, because of the layer below handler doesn't want to have a concerning about any other tenant.
The domain (and usecase) layer should solve an application concerning of specified tenant simply.

I think maybe the concept of FilterByTenant in the usecase layer is an unnecessary repetition and should belong to lower levels like repositories?

Yes, I think better to put FilterByTenant to the repository.
You can inject tenant_id to repository when it is initialized like following.

repo := NewUserRepository(ctx, tenant_id)

But, I think better to treat tenant_id as a context data.
I said the multi-tenancy application's tenant_id is to solve application boundary, I think it is the same as an application context data.

So, I will try to implement FilterByTenant as following:

repo := NewUserRepository(ctx)

---

type UserRepository strurct {
   ctx context.Context
}

func (r *UserRepository) FilterByTenant() *Users {
    tenant_id := ctx.Value('tenant_id')
    ...
}

from 8am.

hatajoe avatar hatajoe commented on August 11, 2024 1

I close this, thanks.

from 8am.

Related Issues (1)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.