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

Decide whether django should have explicit or magic binding to views. #72

Closed
meadsteve opened this issue Sep 2, 2020 · 2 comments
Closed

Comments

@meadsteve
Copy link
Owner

meadsteve commented Sep 2, 2020

Magic (the current implementation):

from .dependency_config import container


@container.bind_view
def index(request, dep: SomeService):
    return HttpResponse(f"service says: {dep.get_message()}")

# Or if you prefer class based views

@container.bind_view
class CBVexample(View):
    def get(self, request, dep: SomeService):
        return HttpResponse(f"service says: {dep.get_message()}")

vs. explicit:

from lagom import injectable
from .dependency_config import container


@container.bind_view
def index(request, dep: SomeService=injectable):
    return HttpResponse(f"service says: {dep.get_message()}")

# Or if you prefer class based views

@container.bind_view
class CBVexample(View):
    def get(self, request, dep: SomeService=injectable):
        return HttpResponse(f"service says: {dep.get_message()}")
@meadsteve meadsteve added this to the Stable django integration milestone Sep 2, 2020
@meadsteve
Copy link
Owner Author

or new option both:
bind_view and magic_bind_view

@meadsteve
Copy link
Owner Author

resolved in pending release

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant