Cross Module Dependency Injection

Matthew Madson project.jigsaw at matthewmadson.com
Sun Oct 9 00:20:40 UTC 2016


Hi there Project Jigsaw Devs,

I was viewing a recent talk posted to the vjug on Jigsaw and had a question
about cross module service dependencies.

Basically I was wondering if the functionality of the ServiceLoader could
be abstracted away using dependency injection (CDI or otherwise).

For example, if I have a CLI module which uses ServiceLoader to obtain
implementations of some dictionary service api, and one of the
implementations requires a DataSource, I would like to declare that
dependency on the DataSource in the ctor of the
DbBackedDictionaryServiceImpl perhaps with an @Inject annotation and have
(perhaps the module system?) automatically look for a suitable providers of
the DataSoruce using the ServiceLoader. Alternatively I could perhaps
declare @Inject on a Set or List of DataSource to support multiple
DataSources.

Basically I'm interested in moving the dependencies provided by the
ServiceLoader into the constructor to make them more explicit.

Thanks for all the hard work, I can't wait to have modules in Java!

Kind Regards,
Matthew Madson


More information about the jigsaw-dev mailing list