diff --git a/sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java b/sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java index 05373da1..f8d37b3f 100644 --- a/sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java +++ b/sdk-core/src/main/java/dev/restate/sdk/core/RestateEndpoint.java @@ -238,6 +238,24 @@ private ServiceDefinitionFactoryDiscovery() { @SuppressWarnings("unchecked") public static ServiceDefinitionFactory discoverServiceDefinitionFactory( Object service) { + if (service instanceof ServiceDefinitionFactory) { + // We got this already + return (ServiceDefinitionFactory) service; + } + if (service instanceof ServiceDefinition) { + // We got this already + return new ServiceDefinitionFactory<>() { + @Override + public ServiceDefinition create(Object serviceObject) { + return (ServiceDefinition) serviceObject; + } + + @Override + public boolean supports(Object serviceObject) { + return serviceObject == service; + } + }; + } return Objects.requireNonNull( ServiceDefinitionFactorySingleton.INSTANCE.discoverFactory(service), () ->