Comments (7)
1.0.13 added an overload that allows this configuration at the server, both on the input and the return
I think that covers everything here, so I'm marking it as completed by 18ef9be - if I'm wrong, ping me and we can reopen.
from protobuf-net.grpc.
Are you talking about something that already exists in the main gRPC library, that I'm not exposing - or are you talking about something bespoke and new?
For the first: indeed I haven't done anything extra there; show me the API and I'll consider it
For the second: what would you propose?
from protobuf-net.grpc.
You'll likely want to expose it in your AddCodeFirstGrpc ext method:
public static void AddCodeFirstGrpc(this IServiceCollection services, Action<GrpcServiceOptions> configureOptions=null)
{
services.AddGrpc(configureOptions);
services.TryAddEnumerable(ServiceDescriptor.Singleton(typeof(IServiceMethodProvider<>), typeof(CodeFirstServiceMethodProvider<>)));
}
So it can be added like:
services.AddCodeFirstGrpc(options => options.Interceptors.Add<MyInterceptor>());
from protobuf-net.grpc.
Yeah, It will be very good to wide AddCodeFirstGrpc with "configureOptions", but it's not critical.
I can use the code like this for it:
public static class GZipCodeFirstGrpc
{
public static void AddGZipCodeFirstGrpc(this IServiceCollection services)
{
var gzipCompressionProvider = new GzipCompressionProvider(CompressionLevel.Optimal);
Action<GrpcServiceOptions> configureOptions = e =>
{
e.CompressionProviders.Add(gzipCompressionProvider);
e.Interceptors.Add(typeof(TestInterceptor));
};
services.Configure(configureOptions).AddCodeFirstGrpc();
}
}
But I have no idea how to add interceptors via protobuf-net.Grpc
on the client side.
And in general, interceptors cannot be configured to catch exceptions which are generated by a code.
ASP.NET Core has great mechanism of controllers' exceptions catching by the custom exception filters. But it doesn't work with the grpc calls (I've tried to realize).
The main idea is connected with the DRY principle - I don't want to repeat try-catch blocks in all grpc calls, but I want to realize it once. It could be realized on the server side by wrapping in try-catch UnaryServerHandler
method in the Interceptor and adding it through AddCodeFirstGrpc
on the server side, but no current way to add on the client side. And, of course, If I use ASP.NET Core + gRPC, I want to use well-working exception handling mechanism which is realized in the ASP.NET Core.
Maybe, do you know the way to add ASP,NET Core exception handling (have a code examples - it's an offtop)? And also it could be great to add mechanism of interceptors adding on the client side.
Thank you.
from protobuf-net.grpc.
Potentially, It could be added here (interceptors for the grpc client) in the
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TService CreateGrpcService<TService>(this ChannelBase client, ClientFactory? clientFactory = null)
where TService : class
=> (clientFactory ?? ClientFactory.Default).CreateClient<TService>(client.CreateCallInvoker());
You could rewrite it like:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TService CreateGrpcService<TService>(this ChannelBase client, ClientFactory? clientFactory = null, params Interceptor[] interceptors)
where TService : class
=> (clientFactory ?? ClientFactory.Default).CreateClient<TService>(interceptors.Length > 0 ? client.CreateCallInvoker().Intercept(interceptors) : client.CreateCallInvoker());
or
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TService CreateGrpcService<TService>(this ChannelBase client, ClientFactory? clientFactory = null, params Interceptor[] interceptors)
where TService : class
=> (clientFactory ?? ClientFactory.Default).CreateClient<TService>(interceptors.Length > 0 ? client.Intercept(interceptors) : client.CreateCallInvoker());
I'll try to run this code to check what's better to use.
from protobuf-net.grpc.
Marc, I think, you also should add interceptors on the client side. Earlier I wrote the code examples which could be used:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TService CreateGrpcService<TService>(this ChannelBase client, ClientFactory? clientFactory = null, params Interceptor[] interceptors)
where TService : class
=> (clientFactory ?? ClientFactory.Default).CreateClient<TService>(interceptors.Length > 0 ? client.CreateCallInvoker().Intercept(interceptors) : client.CreateCallInvoker());
or
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TService CreateGrpcService<TService>(this ChannelBase client, ClientFactory? clientFactory = null, params Interceptor[] interceptors)
where TService : class
=> (clientFactory ?? ClientFactory.Default).CreateClient<TService>(interceptors.Length > 0 ? client.Intercept(interceptors) : client.CreateCallInvoker());
On the server side Action<GrpcServiceOptions>
is really enough.
from protobuf-net.grpc.
@GoNextGroup k; let's consider this (#22) "server-side", and we'll take the client-side conversation to #26
from protobuf-net.grpc.
Related Issues (20)
- ImplicitFields.AllPublic, the member order is alphabet? HOT 2
- Is removing a property from a datacontract Class (not currently used by The client) a breaking Change? HOT 2
- [Question] reject request without paying deserialization cost HOT 10
- Supports generating order values through C# analyzers
- Service Method Input Parameter of Type int Throws Exception
- Stream file from client to server in code first HOT 16
- Empty List converted to null? HOT 2
- Integer overflow for uint HOT 6
- Generate .proto files during build time from a .NET contract assembly HOT 3
- AOT support when using AddSubType HOT 4
- How to use polymorphism on return type of grpc code first service? HOT 5
- Question: Possibilities of usage grpc Reflection with custom Marshallers HOT 7
- protobuf-net and Blazor Trimming - good practices to follow? HOT 2
- Is it protobuf-net.Grpc 1.1.1 compatible with protobuf-net 3.2.30? HOT 2
- Problem with reflection for methods with many enums HOT 6
- MapGrpcService() called over multiple grpc services which are part of same dot net service, these calls cause startup delay HOT 25
- using protobuf-nt.grpc without .proto files with jwt authentication HOT 3
- DateOnly support HOT 2
- Support DataAnnotations Validation
- SchemaGenerator, globally set compatability level
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from protobuf-net.grpc.