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

added container hooks #237

Merged
merged 5 commits into from
Aug 15, 2018
Merged

added container hooks #237

merged 5 commits into from
Aug 15, 2018

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Aug 12, 2018

This PR adds new container hooks.

The three hooks are:

  • on bind
  • on make
  • on resolve

you can set various bindings on the container through classes or strings. An example would be to add a binding on the container whenever you make the Request object. This is awesome for testing purposes:

def set_path_on_request(self, request, container)
    request.path = '/anewroute'
    print('YAY')

...

def boot(self):
    self.on_make(Request, set_path_on_request)

NOTE:

The container hook is always passed 2 parameters: the object bing binded or made or resolved, and the container. So anytime you make a function for a hook, it needs those 2 parameters.


Now everytime in your application you "make" the Request object through self.app.make('Request') or something similar, you will fire that function.

This is the same for bind and resolve:

def boot(self):
    self.on_make(Request, set_path_on_request)
    self.on_bind(Request, set_path_on_request)
    self.on_resolve(Request, set_path_on_request)

You can also have a bunch of these since it's just building a dictionary:

def boot(self):
    self.on_resolve(Request, set_path_on_request)
    self.on_resolve(User, set_path_on_request)
    self.on_resolve(View, set_path_on_request)

@josephmancuso josephmancuso added the next minor Issue scheduled for the next minor release label Aug 12, 2018
@josephmancuso josephmancuso self-assigned this Aug 12, 2018
@josephmancuso josephmancuso requested a review from a team August 12, 2018 15:29
@coveralls
Copy link

coveralls commented Aug 12, 2018

Coverage Status

Coverage increased (+0.06%) to 91.64% when pulling 0abf010 on add-container-hooks into 2faae99 on master.

aisola
aisola previously approved these changes Aug 13, 2018
@josephmancuso josephmancuso merged commit 80523cb into master Aug 15, 2018
@josephmancuso josephmancuso deleted the add-container-hooks branch August 16, 2018 03:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
next minor Issue scheduled for the next minor release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants