Add a strongly typed ServerlessHub#267
Conversation
lfshr
left a comment
There was a problem hiding this comment.
Thanks for picking up my slack here! Have a couple of comments.
| namespace FunctionApp | ||
| { | ||
| public class SimpleChat : ServerlessHub | ||
| public class SimpleChat : ServerlessHub<SimpleChat.IChatClient> |
There was a problem hiding this comment.
Would it not be better to copy & paste the bidirectional-chat example, and highlight the fact that it's a strongly typed example? (eg. strongly-typed-bidirectional-chat)
|
|
||
| public interface IChatClient | ||
| { | ||
| public Task newConnection(NewConnection newConnection); |
| private Task<ServiceHubContext<T>> GetAsync<THub, T>() where THub : ServerlessHub<T> where T : class | ||
| { | ||
| return _strongTypedHubServiceProvider.GetRequiredService<ServerlessHubContext<THub, T>>().HubContextTask; | ||
| } |
There was a problem hiding this comment.
I prefer this signature for GetAsync. As it stands though it's currently never used.
| public dynamic GetAsync(Type THubType, Type TType) | ||
| { | ||
| var genericType = typeof(ServerlessHubContext<,>); | ||
| Type[] typeArgs = { THubType, TType }; | ||
| var serverlessHubContextType = genericType.MakeGenericType(typeArgs); | ||
| dynamic serverlessHubContext = _strongTypedHubServiceProvider.GetRequiredService(serverlessHubContextType); | ||
| return serverlessHubContext.HubContextTask.GetAwaiter().GetResult(); | ||
| } |
There was a problem hiding this comment.
Does this need to be dynamic? We seem to know all the types at compile-time.
| <ProjectReference Include="C:\Users\zityang\source\repos\azure-signalr\src\Microsoft.Azure.SignalR.Management\Microsoft.Azure.SignalR.Management.csproj" /> | ||
| <ProjectReference Include="C:\Users\zityang\source\repos\azure-signalr\src\Microsoft.Azure.SignalR.Common\Microsoft.Azure.SignalR.Common.csproj" /> |
| { | ||
| AccessKey[] AccessKeys { get; } | ||
|
|
||
| public dynamic GetAsync(Type THubType, Type TType); |
There was a problem hiding this comment.
I'm not quite understanding the necessity for this to be separated from IServiceHubContextStore.GetAsync(string hubName). Is this worth documenting?
| { | ||
| var claims = GetClaims(req.Headers["Authorization"]); | ||
| return NegotiateAsync(new NegotiationOptions | ||
| var result = await NegotiateAsync(new NegotiationOptions |
There was a problem hiding this comment.
The NegotiateAsync method returns ValueTask for strongly-typed hub.
|
Linking #131 |
| return true; | ||
| } | ||
| var baseType = type.BaseType; | ||
| while (baseType != null) |
There was a problem hiding this comment.
type.IsSubclassOf(typeof(ServerlessHub<>)) doesn't work?
There was a problem hiding this comment.
type.IsSubclassOf(typeof(ServerlessHub<>))doesn't work?
Doesn't work on an open generic I'm afraid!
|
Hi @lfshr @phantomcosmonaut This project has been merged into a mono repo, please go here for the update of the pr: Azure/azure-sdk-for-net#25075. And the repo will be archived in the future. |
No description provided.