コード例 #1
0
ファイル: ServerExtensions.cs プロジェクト: GreatGeorge1/Grpc
 public static IServiceCollection AddGrpcServer <TServiceInterface, TServiceImplementation>(
     this IServiceCollection serviceCollection,
     GrpcServerOptions options
     )
     where TServiceInterface : class, IGrpcService
     where TServiceImplementation : class, IGrpcService, TServiceInterface
 {
     return(serviceCollection.AddGrpcServer <TServiceInterface, TServiceImplementation>(options, Serializer));
 }
コード例 #2
0
        public static IServiceCollection AddGrpcServer <TServiceInterface, TServiceImplementation>(
            this IServiceCollection serviceCollection,
            GrpcServerOptions options,
            ISerializer serializer
            )
            where TServiceInterface : class, IGrpcService
            where TServiceImplementation : class, IGrpcService, TServiceInterface
        {
            serviceCollection.AddScoped <TServiceInterface, TServiceImplementation>();
            serviceCollection.AddSingleton <GrpcHost <TServiceInterface> >(
                appServices => GrpcHostFactory.Create <TServiceInterface>(appServices, options, serializer)
                );

            serviceCollection.AddSingleton <IHostedService, GrpcBackgroundService <TServiceInterface> >();
            return(serviceCollection);
        }