Contributing an Alias
To contribute a new service to the Alias service, you must first decide on a logical name. Often, this is the name of the service interface implemented by the service.
You can then contribute into the Infrastructure service's configuration:
public static void contributeAlias(@InjectService("MyService") MyService myService, Configuration<AliasContribution> configuration) { configuration.add(AliasContribution.create(MyService.class, myService)); }
The above example follows a typical pattern; the service to be vended is injected into the contributor method, using the explicit InjectService annotation. A contribution is made providing the service type.
Notice that the contribution doesn't have to be a service; you can just instantiate an object inside the contribution method and contribute that. That's what we're doing in the example, though we're using a create() static method rather than new (just to smooth out some Java Generics ugliness).
Contributing to AliasOverrides
To override a service, you need to know its service interface name.
You can then make a contribution to the AliasOverrides service configuration, as described in the previous section.
The object contributed as an override will mask the default contribution.