-
Notifications
You must be signed in to change notification settings - Fork 26
[Autumn] Dependency injection after ContextInitializer has done its part. #69
Description
I have a case where I need to fill VerticalGroup with a complex items and I chose to go with individual controller instance per view item to encapsulate view logic and item model reference within. So this controller class has a lot of similarities with ViewController, like it has number of LML annotations and also should have injected dependencies to system-wide services/components.
I remember the discussion #40 and it gave me a good point to keep Context not disposed in case I will need to obtain any system component in a future. And so I can, by calling Context#getComponent(Class<?>), but I start thinking if there is a way to automate this process. I mean in that fancy elegant way like ContextInitializer#initiateComponents() does to resolve dependencies, but this time on demand for any specific instance with Autumn annotations like @Inject (maybe even for @OnEvent/@OnMessage, but this could lead to memleaks due to an each instance should be unsubscribed manually).
ContextInitializer is fully dedicated to only initialize Context and is not usable after. Feels like if there should be some injector service, then it better be outside of ContextInitializer and available system wide so anyone can utilize dependency injection later.
@czyzby what do you think, is it a good idea or even is it possible to add such utility functionality to the library core?