[
https://issues.apache.org/jira/browse/LENS-461?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14394643#comment-14394643
]
Himanshu Gahlaut commented on LENS-461:
---------------------------------------
Full inversion of control will help. Currently our resource classes have taken
up the responsibility of pulling the required service instance through
LensServices singleton class in their no argument constructor. This is why we
aren't able to pass a mock service into resource classes or pass a new instance
per test into resource classes. We need to take this responsibility of creation
of collaboration graph away from Resource classes. Instead of this, resource
classes should just add service as a dependency and ask for the same via their
constructor (dependency injection). Also the services should do the same. They
should just ask for what they are dependent on, instead of getting into
business of constructing the same. Once this happens, every test can create its
individual instance of service and its collaboration graph.
Jersey might have inbuilt support for injection of services into resource
classes via implementation of some ResourceProvider methods which I'm not aware
of. We can explore jersey support for the same. Even if it has support, I'm not
sure how the entire collaboration graph will be instantiated.
OR
We can use jersey with IOC framework, Guice. LensServletContextListener can
extend from GuiceServletContextListener to initialize and complete guice
binding of service instances in contextInitialized method. It will be the
responsibility of Guice to inject services into resources and also make sure
that only one instance of all services is created in life cycle of lens server
without coding the classes with singleton pattern. Guice will also own the
responsibility of creation of entire collaboration graph of service instances.
> Review usage of static singletons
> ---------------------------------
>
> Key: LENS-461
> URL: https://issues.apache.org/jira/browse/LENS-461
> Project: Apache Lens
> Issue Type: Sub-task
> Reporter: Jaideep Dhok
>
> We have added several static singleton variables. These make it tough to
> write tests which can be run in isolation. The scope of this task is to
> identify and possibly fix statics.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)