OctopusDeploy / Halibut

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

Add support for generic services #510

Closed APErebus closed 3 months ago

APErebus commented 1 year ago

Background

Halibut doesn't currently support generic services (i.e. IMyService<T>). This is due to how the service name is serialized in the request message, it just uses Type.Name, which doesn't include any generic type argument information, just the number of generic type args (i.e. IMyService`1).

This means that the service can't be correctly resolved as IMyService<int> and IMyService<string> are identified in the request message as the same service.

Results

This PR changes the TypeRegistry and the HalibutProxy to use a new extension method, GetGenericQualifiedName() as the service name, rather than the .Name property.

This new extension method adds the generic type args to the name in the format IMyService`2[Arg1,Arg2]. If a generic type arg is also generic, it will build the same structure like this IMyService`2[MyGenericType`1[string],string].

Also, I have updated the TypeRegistry to find all derived types if a service method parameter is abstract. That is, if the method signature is void MyMethod(BaseType base) and there are two derived types of BaseType, then those types are also registered.

I have also added new unit tests covering the new generic services. I don't have enough knowledge of Halibut testing to understand what I need to do regarding the latest/previous version test cases, but this should be backwards compatible for existing services.

How to review this PR

Quality :heavy_check_mark:

Pre-requisites