[ 
https://issues.apache.org/jira/browse/LOG4J2-3496?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17537132#comment-17537132
 ] 

Matt Sicker edited comment on LOG4J2-3496 at 5/15/22 4:23 AM:
--------------------------------------------------------------

[~vy] see 
[https://github.com/apache/logging-log4j2/blob/5a0eafd10956738d8ab4ce00325651a29ec58bce/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/InjectorTest.java#L803-L811]
 for a sample of the various injections when using plugins. There's also 
generic support for Optional when using injectable classes directly. Combined 
with plugin stubs in 
[https://github.com/apache/logging-log4j2/tree/master/log4j-plugins-test/src/main/java/org/apache/logging/log4j/plugins/test/validation/generic]


was (Author: jvz):
[~vy] see 
[https://github.com/apache/logging-log4j2/blob/5a0eafd10956738d8ab4ce00325651a29ec58bce/log4j-plugins-test/src/test/java/org/apache/logging/log4j/plugins/di/InjectorTest.java#L803-L811]
 for a sample of the various injections when using plugins. There's also 
generic support for Optional when using injectable classes directly.

> Support injection via container types
> -------------------------------------
>
>                 Key: LOG4J2-3496
>                 URL: https://issues.apache.org/jira/browse/LOG4J2-3496
>             Project: Log4j 2
>          Issue Type: New Feature
>          Components: Plugins
>            Reporter: Volkan Yazici
>            Assignee: Matt Sicker
>            Priority: Major
>             Fix For: 3.0.0
>
>
> Plugin system should support the injection via container types. Since this is 
> not currently the case, whenever a, for instance, collection of plugins need 
> to be injected (e.g., Pattern and JSON Template Layouts), ad-hoc access to 
> {{PluginManager}} or {{PluginUtils}} is needed. This approach has certain 
> drawbacks:
> * Duplication of ad-hoc code
> * Not aligned with the way plugins are loaded, that is, via {{@Inject}}
> * Impossible to test
> h3. Container types
> Ideally, the plugin system should support injection via the following 
> container types:
> * {{Optional<P>}}
> * {{Collection<P>}}
> * {{Iterable<P>}}
> * {{Set<P>}}
> * {{Stream<P>}}
> * {{List<P>}}
> * {{Map<N, P>}}
> Above {{P}} denotes the type the plugin is assignable from and {{N}} denotes 
> the plugin name.
> h3. Ordering problem
> A {{@PluginOrder}} annotation needs to be introduced to address the following 
> corner cases:
> * In the case of {{Optional<P>}}, if there are multiple matches, the first 
> one needs to be picked.
> * In the case of collection and map types, elements need to be sorted.
> Sorting can be done in the following way:
> * If one or more of the matches are annotated with {{@PluginOrder}}, they 
> will have the precedence and get sorted according to {{@PluginOrder}} values.
> * The rest will be sorted according to their discovery order.
> The order in collection types can be preserved using the following 
> implementations:
> * {{Set}} -> {{LinkedHashSet}}
> * {{Map}} -> {{LinkedHashMap}}
> * {{Collection}}, {{Iterable}}, {{Stream}} -> {{List}}



--
This message was sent by Atlassian Jira
(v8.20.7#820007)

Reply via email to