Autowire interface with one implementation
One feature that can reduce some boilerplate, is that we create automatically a service for each interface and point to the implementation automatically when there is only one.
For example :
class UserProvider(ABC)
class DatabaseUserProvider(UserProvider)
Don't have to write
container[UserProvider] = DatabaseUserProvider
What do you think ?
Sounds like a great idea, any chance you have a rough idea how to implement this?
Whilst this is potentially a nice feature I'm hesitant on two fronts:
-
It's less explicit. There's now an implicit behaviour about what gets loaded. Currently in lagom all the loading is done explicitly so this is a fairly big change.
-
This may actually be surprisingly hard to implement in a thorough way. Python classes have a
__subclasses__property which would contain the "one implementation". However__subclasses__only contains classes that have been loaded. So it's possible that a second subclass exists but it's not yet been loaded. This means that lagom would likely need to implement some directory scanning to find all possible classes.