|
35 | 35 | import org.eclipse.sisu.Typed;
|
36 | 36 |
|
37 | 37 | /**
|
38 |
| - * DefaultModelProcessor |
| 38 | + * |
| 39 | + * Note: uses @Typed to limit the types it is available for injection to just ModelProcessor. |
| 40 | + * |
| 41 | + * This is because the ModelProcessor interface extends ModelLocator and ModelReader. If we |
| 42 | + * made this component available under all its interfaces then it could end up being injected |
| 43 | + * into itself leading to a stack overflow. |
| 44 | + * |
| 45 | + * A side-effect of using @Typed is that it translates to explicit bindings in the container. |
| 46 | + * So instead of binding the component under a 'wildcard' key it is now bound with an explicit |
| 47 | + * key. Since this is a default component this will be a plain binding of ModelProcessor to |
| 48 | + * this implementation type, ie. no hint/name. |
| 49 | + * |
| 50 | + * This leads to a second side-effect in that any @Inject request for just ModelProcessor in |
| 51 | + * the same injector is immediately matched to this explicit binding, which means extensions |
| 52 | + * cannot override this binding. This is because the lookup is always short-circuited in this |
| 53 | + * specific situation (plain @Inject request, and plain explicit binding for the same type.) |
| 54 | + * |
| 55 | + * The simplest solution is to use a custom @Named here so it isn't bound under the plain key. |
| 56 | + * This is only necessary for default components using @Typed that want to support overriding. |
| 57 | + * |
| 58 | + * As a non-default component this now gets a negative priority relative to other implementations |
| 59 | + * of the same interface. Since we want to allow overriding this doesn't matter in this case. |
| 60 | + * (if it did we could add @Priority of 0 to match the priority given to default components.) |
39 | 61 | */
|
40 |
| -@Named |
| 62 | +@Named( "core-default" ) |
41 | 63 | @Singleton
|
42 | 64 | @Typed( ModelProcessor.class )
|
43 | 65 | public class DefaultModelProcessor
|
|
0 commit comments