Code-first gRPC #2751
flibbertigibbet-uk
started this conversation in
General
Code-first gRPC
#2751
Replies: 2 comments
-
This feature is a pure convenience over what is there today but AFAIK code first grpc should just work with service discovery. Is that what you are asking? |
Beta Was this translation helpful? Give feedback.
0 replies
-
You can do this by adapting the creator of the AddGrpcClient in the This would look something like this: public static IHttpClientBuilder AddCodeFirstGrpcReference<TClient>(this IServiceCollection services, string address, string? healthCheckName = null, HealthStatus failureStatus = default)
where TClient : class
{
ArgumentNullException.ThrowIfNull(services);
if (!Uri.IsWellFormedUriString(address, UriKind.Absolute))
{
throw new ArgumentException("Address must be a valid absolute URI.", nameof(address));
}
var uri = new Uri(address);
var builder = services.AddGrpcClient<TClient>(o =>
{
o.Address = uri;
o.Creator = invoker => invoker.CreateGrpcService<TClient>();
});
AddGrpcHealthChecks(services, uri, healthCheckName ?? $"{typeof(TClient).Name}-health", failureStatus);
return builder;
} The key change here is with the creator adding |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am considering migrating a C# Core solution to Aspire and this solution currently uses a library that implements code-first gRPC https://protobuf-net.github.io/protobuf-net.Grpc/gettingstarted and https://github.com/protobuf-net/protobuf-net.Grpc
Has anyone been down this route?
I notice @JamesNK (co-author of protobuf-net.Grpc) has been active in this repository and previously discussed support of named gRPC end-points. https://github.com/dotnet/aspire/issues/186 Is this delayed feature relevant to migrating protobuf-net.Grpc based application code to Aspire?
And before hitting the submit button I did some extra searching and found this open issue https://github.com/dotnet/aspire/issues/898 which references the eShop sample. The sample code includes application level extension methods to support gRPC service discovery. I think I can just lift the gRPC extension method from the eShop code and replace:
services.AddGrpcClient<TClient>
with
services.AddCodeFirstGrpcClient<TClient>
Beta Was this translation helpful? Give feedback.
All reactions