antonrh / anydi

Python Dependency Injection
https://anydi.readthedocs.io/
MIT License
34 stars 0 forks source link

Default to a scope when none is provided in auto-registration mode #83

Closed attilavetesi-epam closed 5 months ago

attilavetesi-epam commented 5 months ago

The code at: https://github.com/antonrh/anydi/blob/17154b88231cc339fe118afa1ab2ebadbbde6681/anydi/_container.py#L396 defaults to scope None when there are no sub-dependencies with defined scopes.

This (as far as I understand) enforces that a scope decorator or manual registration is always mandatory on types, otherwise automatic registration cannot happen, which (I think) invalidates a bit the automatic registration itself for types that do not have any sub-dependencies (i.e. they can be injected by themselves).

Would it be possible to default to a scope (e.g. transient) thus making automatic registration more seamless?

antonrh commented 5 months ago

Hi @attilavetesi-epam, thank you for the first issue. You are right, and I was thinking of doing that since I encountered the same issue in a project when using non-strict mode. Unfortunately, I'll be back in 10 days from vacation and will add this. Meanwhile, you can use scope decorators.

antonrh commented 5 months ago

Available in 0.23.0