Open jpdna opened 7 years ago
This is where the dependency injection stuff comes in, you don't have to call new. In fact, as you've noticed, the constructors are all package private, so you can't.
Add Converter<AlignmentRecord, ReadAlignment>
as a parameter to your constructor and an @Inject
annotation and it will be provided by Guice.
@Inject
MyClass(final Converter<AlignmentRecord, ReadAlignment> converter) { ... }
Or to do it directly,
Injector injector = Guice
.createInjector(new Ga4ghModule());
Converter<AlignmentRecord, ReadAlignment> converter = injector
.getInstance(Key.get(new TypeLiteral<Converter<AlignmentRecord, ReadAlignment>>() {}));
Do you happen to have an example injecting into a scala class? Google seems to say yes possible with scala, but if you have an example handy....
Guice is already used in ADAM for injecting commands into ADAMMain
I can write up a scala example. What is the class that would be using the converter? Or should I work up an example in the shell?
Note https://github.com/bigdatagenomics/bdg-convert/issues/27 has been fixed; this repository has been migrated to bdg-convert as a new Maven module. I'll leave this repo as is for a week or so then close/migrate any issues upstream.
@heuermh I am trying to use bdg-ga4gh-convert 'alignmentConverter' to map ( or maybe collect to array and map locally) an AlignmentRecordRDD.rdd to ga4gh JSON.
To do so, I need to create a new alignmentConverter in a package outside of
org.bdgenomics.convert.ga4gh
( we could create an AlignmentRecordRDDtoJSON converter inside bdg-convert-ga4gh, but I think better to be able to just use the basic object per type converters as a library.)I try to do this in in scala in an outside package after importing:
I try:
the above fails and says "not accessible from this location" for
AlignmentRecordToReadAlignment
and the the othernew
statements aboveHow can I instantiate a new AlignmentRecordToReadAlignment?
Should the constructor for AlignmentRecordToReadAlignment by accessible outside the bdg-convert-ga4gh package?
I do notice how AlignmentRecordToReadAlignment is not public while: public abstract class AbstractConverter<S, T> implements Converter<S, T>, Serializable { is public, but I still clearly I dont' understand how to use AlingmentRecordToReadAlignment from outside the package, and can't see to correct create it as an instance of the public base package.