SaturnFramework / Saturn

Opinionated, web development framework for F# which implements the server-side, functional MVC pattern
https://saturnframework.org
MIT License
703 stars 108 forks source link

use_grpc does not work with multiples services #304

Open joshuapassos opened 3 years ago

joshuapassos commented 3 years ago

Based from sample here

Add someone new service

let app = application {
  no_router
  listen_local 10042 (fun opts -> opts.Protocols <- HttpProtocols.Http2)
  use_grpc Service1
  use_grpc Service2
}

Only Service2 works

joshuapassos commented 3 years ago

To workaround, I created a new grpc to use interceptors and multiples services

type Saturn.Application.ApplicationBuilder with
    [<CustomOperation("grpc")>]
    member __.UseCustomGrpc(state) =
        let configureServices (services: IServiceCollection) =
            // services.AddGrpc(fun opt -> opt.Interceptors.Add<InterceptorTest>()) |> ignore
            services.AddGrpc() |> ignore
            services

        let configureApp (app: IApplicationBuilder) =
            app.UseRouting()

        let configureGrpcEndpoint (app: IApplicationBuilder) =
            app.UseEndpoints (fun endpoints -> endpoints.MapGrpcService<Service1>() |> ignore) |> ignore
            app.UseEndpoints (fun endpoints -> endpoints.MapGrpcService<Service2>() |> ignore) |> ignore
            app.UseEndpoints (fun endpoints -> endpoints.MapGrpcService<Service3>() |> ignore) |> ignore
            app

        { state with
            AppConfigs = configureApp::configureGrpcEndpoint::state.AppConfigs
            ServicesConfig = configureServices::state.ServicesConfig
        }
let app = application {
  no_router
  listen_local 10042 (fun opts -> opts.Protocols <- HttpProtocols.Http2)
  grpc
}