[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [sisu-dev] @Qualifier not being indexed
|
Forgot to mention you can also @Inject the BeanLocator which lets you do programatic lookups
On 11 Jan 2013, at 23:49, Stuart McCulloch wrote:
> On 11 Jan 2013, at 23:16, Jonathan Doklovic wrote:
>
>> Let me ask this a different way....
>>
>> Is there a way in sisu to easily get a collection of classes (not objects) that implement a given interface and/or have a specific annotation?
>>
>> For example, I have classes that implement ConfigurationEntry. I need to find all of those classes (across bundles) and pass their class objects to a gson type adapter. These classes should NOT be instantiated/wired by guice.
>
> If you want details of all implementations of ConfigurationEntry without instantiating them then you can use:
>
> @Inject Iterable<BeanEntry<Named, ConfigurationEntry>> entries;
>
> If you want details of all implementations of ConfigurationEntry that have a specific Qualifier then you can use:
>
> @Inject Iterable<BeanEntry<MyQualifier, ConfigurationEntry>> entries;
>
> If you want details of all implementations that have a specific Qualifier then you can use:
>
> @Inject Iterable<BeanEntry<MyQualifier, Object>> entries;
>
> The BeanEntry API lets you query various details such as the implementation class without needing to eagerly instantiate the component:
>
> http://git.eclipse.org/c/sisu/org.eclipse.sisu.inject.git/plain/org.eclipse.sisu.inject/src/org/eclipse/sisu/BeanEntry.java
>
> all the various dynamic Lists/Maps/etc. provided by Sisu are actually driven by BeanEntry under the covers - the only difference is the view onto the BeanEntry sequence.
>
> HTH
>
>> Thanks,
>>
>> - Jonathan
>>
>> On 01/11/2013 01:42 PM, Stuart McCulloch wrote:
>>> On 11 Jan 2013, at 20:25, Jonathan Doklovic wrote:
>>>
>>>> Hi,
>>>>
>>>> I have an annotation that's tagged with @Qualifier and a class that uses my annotation.
>>>> I expected to see a new file in META-INF/sisu for this class, but it doesn't get generated.
>>>> the @Named index is being generated properly just not my custom annotation.
>>>>
>>>> Am I missing something?
>>> The current indexer will pick up other @Qualifiers, but at the moment the qualified class is only added to the @Named index, as from Sisu's perspective it treats any component with a @Qualifier as being implicitly @Named.
>>>
>>> Likewise the container only queries the 'META-INF/sisu/javax.inject.Named' file when performing an indexed scan, because 1) it lists all known qualified components and 2) it is much faster to call getResource on a fixed path than hunt for all resources under the 'META-INF/sisu/' path (plus not all classloaders expose enough information about the underlying resource URLs to perform such a scan). Note this index is only used to list the qualified components needing runtime scanning to avoid having to brute-force scan the classpath, the binding and query features both work off the runtime annotations found when loading the component class.
>>>
>>> Originally the idea was to have a file per-@Qualifier, but the benefit of every qualified component being implicitly @Named and therefore 'META-INF/sisu/javax.inject.Named' list all know qualified components meant this was implemented first - and since the container only needs this file the indexer hasn't yet been extended to write out the other @Qualifier files (although it does have the necessary information to do this). There was a discussion about choosing a different name for this 'any qualified component list', but at the time we already had jars using this format and it also lets us add other @Qualifier files in the future (which would then be subsets of the main javax.inject.Named index).
>>>
>>> So basically you can index components with other @Qualifiers, and query them using those @Qualifiers, but at the moment they only get listed in the canonical 'META-INF/sisu/javax.inject.Named' file.
>>>
>>> HTH
>>>
>>>> - Jonathan
>>>>
>>>> _______________________________________________
>>>> sisu-dev mailing list
>>>> sisu-dev@xxxxxxxxxxx
>>>> http://dev.eclipse.org/mailman/listinfo/sisu-dev
>>> _______________________________________________
>>> sisu-dev mailing list
>>> sisu-dev@xxxxxxxxxxx
>>> http://dev.eclipse.org/mailman/listinfo/sisu-dev
>>
>