Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Consider moving hoisted dependencies into the controller actions #210

Closed
matthewmueller opened this issue Jul 16, 2022 · 0 comments
Closed
Labels
breaking This is a breaking change improvement New feature or request needs decision Need to think more and decide

Comments

@matthewmueller
Copy link
Contributor

Right now you're able to do something like this:

func Load(session *Session, pg *postgres.Client) *Controller {
  return &Controller{w, pg}
}

type Controller struct {
  pg *postgres.Client
  session *session.Session
}

func (c *Controller) Index() {}

And Bud is smart enough to initialize *postgres.Client once on boot and *session.Session per request. This was done to keep the function signature of the actions clean and focused on the inputs and outputs.

Suppose Load was an expensive operation though. It would be very surprising to learn that Load is called every request. I'm now leaning towards something like this:

func (c *Controller) Delete(session *session.Session) error { 
  return session.Logout() 
}

And then separating inputs from dependencies.

See for more discussion: #185 (comment)

@matthewmueller matthewmueller added improvement New feature or request needs decision Need to think more and decide breaking This is a breaking change labels Jul 16, 2022
@livebud livebud locked and limited conversation to collaborators Jul 16, 2022
@matthewmueller matthewmueller converted this issue into discussion #211 Jul 16, 2022

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
breaking This is a breaking change improvement New feature or request needs decision Need to think more and decide
Projects
None yet
Development

No branches or pull requests

1 participant