Skip to content

Use in class #34

Closed
Closed
@chrisgoddard

Description

@chrisgoddard

Hi there!

Quick question - is there a way to use this in the context of a class rather than a function?

Either within a method:

class Example:
    @inject
    def method(self, x = Depends(dependency)):
        ...

or class variable?

@inject
class Example:
    x = Depends(dependency)
    
    def method(self):
        ...

Right now, in the first example, I get the error TypeError: CallModel.solve() got multiple values for argument 'self'

(second example was just another idea - not expected behavior).

Love the library btw - thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions