diff --git a/sample/gRpcSample.Client/Program.fs b/sample/gRpcSample.Client/Program.fs index 20da08ed..c4dd1bcf 100644 --- a/sample/gRpcSample.Client/Program.fs +++ b/sample/gRpcSample.Client/Program.fs @@ -3,14 +3,21 @@ open Shared open System open System.Net.Http open FSharp.Control.Tasks +open Grpc.Net.Client [] let main _ = HttpClientExtensions.AllowUnencryptedHttp2 <- true task { - use http = new HttpClient (BaseAddress = Uri "http://localhost:10042") - let client = http.CreateGrpcService() - let! result = client.MultiplyAsync { X = 12; Y = 4 } + use http = GrpcChannel.ForAddress("http://localhost:10042"); + let calculatorClient = http.CreateGrpcService() + let helloClient = http.CreateGrpcService() + + let! result = calculatorClient.MultiplyAsync { X = 12; Y = 4 } printfn "%i" result.Result + + let! r = helloClient.TestAsync { Parameter = "Saturn" } + printfn "%s" r.Response + return 0 } |> fun t -> t.Result \ No newline at end of file diff --git a/sample/gRpcSample/Shared.fs b/sample/gRpcSample/Shared.fs index 1a3e667a..7c1222a7 100644 --- a/sample/gRpcSample/Shared.fs +++ b/sample/gRpcSample/Shared.fs @@ -6,13 +6,30 @@ open System.Runtime.Serialization [] type MultiplyRequest = - { [] X : int - [] Y : int } + { [] + X: int + [] + Y: int } [] type MultiplyResult = - { [] Result : int } + { [] + Result: int } + +[] +type HelloRequest = + { [] + Parameter: string } + +[] +type HelloResult = + { [] + Response: string } [] type ICalculator = - abstract MultiplyAsync : MultiplyRequest -> ValueTask + abstract MultiplyAsync : MultiplyRequest -> ValueTask + +[] +type IHello = + abstract TestAsync : HelloRequest -> ValueTask diff --git a/sample/gRpcSample/gRpcSample.fs b/sample/gRpcSample/gRpcSample.fs index 33880c03..2a6362f8 100644 --- a/sample/gRpcSample/gRpcSample.fs +++ b/sample/gRpcSample/gRpcSample.fs @@ -9,24 +9,32 @@ open System.Threading.Tasks open Giraffe type MyCalculator() = - interface ICalculator with - member __.MultiplyAsync request = - ValueTask<_> { Result = request.X * request.Y } + interface ICalculator with + member __.MultiplyAsync request = + ValueTask<_> { Result = request.X * request.Y } type MyCalculatorWithDI(serializer: Json.ISerializer) = - interface ICalculator with - member __.MultiplyAsync request = - printfn "Multiply reques serialized: %s" (serializer.SerializeToString request) - ValueTask<_> { Result = request.X * request.Y } + interface ICalculator with + member __.MultiplyAsync request = + printfn "Multiply requests serialized: %s" (serializer.SerializeToString request) + ValueTask<_> { Result = request.X * request.Y } -let app = application { - no_router - listen_local 10042 (fun opts -> opts.Protocols <- HttpProtocols.Http2) - use_grpc MyCalculatorWithDI -} + +type MyHelloWithDI(serializer: Json.ISerializer) = + interface IHello with + member __.TestAsync request = + ValueTask<_> { Response = $"Hello, {request.Parameter}!" } + +let app = + application { + no_router + listen_local 10042 (fun opts -> opts.Protocols <- HttpProtocols.Http2) + use_grpc MyHelloWithDI + use_grpc MyCalculatorWithDI + } [] let main _ = - run app - 0 // return an integer exit code + run app + 0 // return an integer exit code diff --git a/src/Saturn.Extensions.gRPC/Saturn.gRPC.fs b/src/Saturn.Extensions.gRPC/Saturn.gRPC.fs index 28a6f127..deda077e 100644 --- a/src/Saturn.Extensions.gRPC/Saturn.gRPC.fs +++ b/src/Saturn.Extensions.gRPC/Saturn.gRPC.fs @@ -21,6 +21,6 @@ type Saturn.Application.ApplicationBuilder with app.UseEndpoints (fun endpoints -> endpoints.MapGrpcService<'a>() |> ignore) { state with - AppConfigs = configureApp::configureGrpcEndpoint::state.AppConfigs + AppConfigs = configureApp::configureGrpcEndpoint::state.AppConfigs.[1.. state.AppConfigs.Length] ServicesConfig = configureServices::state.ServicesConfig }