Giter Site home page Giter Site logo

Comments (7)

mgravell avatar mgravell commented on August 28, 2024 1

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.

mgravell avatar mgravell commented on August 28, 2024

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.

mythz avatar mythz commented on August 28, 2024

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.

GoNextGroup avatar GoNextGroup commented on August 28, 2024

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.

GoNextGroup avatar GoNextGroup commented on August 28, 2024

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.

GoNextGroup avatar GoNextGroup commented on August 28, 2024

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.

mgravell avatar mgravell commented on August 28, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.