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

Add picobox.ext.enterprise extension #74

Open
ikalnytskyi opened this issue Nov 20, 2023 · 1 comment
Open

Add picobox.ext.enterprise extension #74

ikalnytskyi opened this issue Nov 20, 2023 · 1 comment
Milestone

Comments

@ikalnytskyi
Copy link
Owner

ikalnytskyi commented Nov 20, 2023

One thing I regret about picobox is that it uses non-conventional names for methods (e.g. pass_(), not inject) and classes (e.g. Box, not Container). I'm afraid it might be a too late to change the names.

That's why it's worth considering introducing some picobox.ext.enterprise extension that can expose better names.

How can it look like?

import picobox.ext.enterprise as di
import requests


@di.inject("conf")
@di.inject("requests", as_="session")
def get_resource(uri, session, conf):
    return session.get(conf["base_uri"] + uri)


container = di.Container()
container.add("conf", {"base_uri": "http://example.com"})
container.add("requests", factory=requests.Session, scope=picobox.threadlocal)

with di.use(container):
    get_resource("/resource", requests.Session(), {})
    get_resource("/resource", requests.Session())
    get_resource("/resource")
@ikalnytskyi ikalnytskyi added this to the 4.1.0 milestone Nov 20, 2023
@ikalnytskyi
Copy link
Owner Author

Alternatively, the new interface can be developed in-house while deprecating the old one, which will delegate its calls to the new interface. 🤔 This approach will result in much more readable application code, though the project name will eventually lose its meaning.

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

No branches or pull requests

1 participant