OctopusDeploy / Halibut

| Public | A secure communication stack for .NET using JSON-RPC over SSL.
Other
12 stars 44 forks source link

Make ServiceInvoker async #428

Closed acodrington closed 1 year ago

acodrington commented 1 year ago

Description

This PR adds a InvokeAsync method to IServiceInvoker and ServiceInvoker, as part of [sc-53211]. This allows the ServiceInvoker to invoke async implementations of services with sync interfaces.

Upon succesfully acquiring a lease from the IServiceFactory, InvokeAsync will search for an async method on the registered service which matches the name of requested method, but also follows these conventions:

This feature is dependant on the implementation of IServiceFactory being used (Octopus Server and Tentacle use their own implementations), but we can now register async implementations of sync services in the DelegateServiceFactory:

var serviceFactory = new DelegateServiceFactory();
serviceFactory.Register<IMySyncService, IMyAsyncService>(() => new MyAsyncServiceImpl());

In the above example, there is no formal relationship between IMySyncService and IMyAsyncService, but the async interface must replicate the sync interface whilst adhering to the conventions listed above.

The DelegateServiceFactory will throw an exception upon registration if the async interface does not follow the conventions, via the new AsyncServiceVerifier helper class.

Main changes:

Related to https://github.com/OctopusDeploy/Issues/issues/8266

shortcut-integration[bot] commented 1 year ago

This pull request has been linked to Shortcut Story #53211: 🎉 🎉 🎉 Make Halibut Support Async RPC Calls 🎉 🎉 🎉.

LukeButters commented 1 year ago

The description I think should give an example of the behaviour that this PR adds e.g. an example around how an async service can be supplied and called as well as some details around how it has to be done/what the methods need to look like etc.