Skip to content

Commit

Permalink
Merge pull request #476 from avano/fix-default-configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
avano authored Apr 21, 2023
2 parents 408f92b + 81a460b commit 8981471
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ private ServiceFactory() {
* @param <S> type
*/
public static <S extends Service> S create(Class<S> clazz) {
S service = loadService(clazz);
if (service instanceof ConfigurableService<?>) {
((ConfigurableService<?>) service).defaultConfiguration();
}
return service;
}

private static <S extends Service> S loadService(Class<S> clazz) {
if (ReflectionUtils.isAbstract(clazz) || clazz.isInterface()) {
final ServiceLoader<S> loader = ServiceLoader.load(clazz);
if (loader.stream().findAny().isEmpty()) {
Expand Down Expand Up @@ -68,7 +76,6 @@ public static <S extends Service> S create(Class<S> clazz) {

public static <C extends ServiceConfiguration, S extends ConfigurableService<C>> S create(Class<S> clazz, Consumer<C> config) {
S service = create(clazz);
service.defaultConfiguration();
config.accept(service.getConfiguration());
return service;
}
Expand Down

0 comments on commit 8981471

Please sign in to comment.