diana_grpc 0.15.1
diana_grpc: ^0.15.1 copied to clipboard
gRPC support for the Diana backend framework: dependency-injected protoc-generated services with Diana lifecycle integration.
diana_grpc example #
dependencies:
diana: ^0.15.1
diana_grpc: ^0.15.1
grpc: ^5.0.0
protobuf: ^6.0.0
Generate Dart code from your .proto, then extend the generated service
base. It is a regular singleton injectable — constructor injection,
@Value and lifecycle hooks all apply — and the generated DianaApp
serves it on its own port next to your HTTP controllers:
import 'package:diana/diana.dart';
import 'package:grpc/grpc.dart' show ServiceCall;
import '../src/generated/greeter.pbgrpc.dart';
@GrpcService()
class GreeterService extends GreeterServiceBase {
final String greetingPrefix;
GreeterService(
@Value('app.greeting', defaultValue: 'Hello') this.greetingPrefix);
@override
Future<HelloReply> sayHello(ServiceCall call, HelloRequest request) async =>
HelloReply()..message = '$greetingPrefix, ${request.name}!';
}
A complete app serving gRPC and HTTP side by side is in examples/greeter_grpc. See the gRPC guide.