Exemplo n.º 1
0
        public void ConfigureServices(IServiceCollection services)
        {
            var hostConfig = _configuration.GetSection("Host").Get <HostConfig>();

            services.Configure <KestrelServerOptions>(options =>
            {
                options.Listen(
                    IPAddress.TryParse(hostConfig.WebApiListen, out var webApiAddress) ? webApiAddress : IPAddress.Loopback,
                    hostConfig.WebApiPort != 0 ? hostConfig.WebApiPort : 1209
                    );
                options.Listen(
                    IPAddress.TryParse(hostConfig.RpcListen, out var rpcAddress) ? rpcAddress : IPAddress.Loopback,
                    hostConfig.RpcPort != 0 ? hostConfig.RpcPort : 1120,
                    listenOptions =>
                {
                    listenOptions.Protocols = HttpProtocols.Http2;
                });
            });
            services.AddSingleton <UnverifiedMessagePool>();
            services.AddSingleton <NodeService>();
            services.AddSingleton <BlockService>();
            services.AddSingleton <MessageService>();
            services.AddControllers();
            services.AddCodeFirstGrpc(options => options.ResponseCompressionLevel = CompressionLevel.Optimal);
            services.TryAddSingleton(BinderConfiguration.Create(binder: new RpcBinder(services)));
            services.AddCodeFirstGrpcReflection();
        }
Exemplo n.º 2
0
 public static void AddGrpcClientInfrastructure(this IServiceCollection services)
 {
     services.AddTransient <AuthorizationGrpcClientInterceptor>();
     services.AddTransient <ServerExceptionsGrpcClientInterceptor>();
     services.AddTransient <GrpcWebHandler>(provider => new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));
     services.AddSingleton <ClientFactory>(ClientFactory.Create(BinderConfiguration.Create(marshallerFactories: new[] { ProtoBufMarshallerFactory.Create(RuntimeTypeModel.Create().RegisterApplicationContracts()) }, binder: new ProtoBufServiceBinder())));
 }
Exemplo n.º 3
0
        public static void AddServiceStackGrpc(this IServiceCollection services)
        {
            var marshallers = new List <MarshallerFactory> {
                GrpcMarshallerFactory.Instance,
                ProtoBufMarshallerFactory.Default,
            };
            var binder = BinderConfiguration.Create(marshallers);

            services.AddSingleton(binder);
            services.AddCodeFirstGrpc();
        }
Exemplo n.º 4
0
 public static void AddGrpcClientInfrastructure(
     this IServiceCollection services,
     Assembly assemblyToScanForDataContracts)
 {
     services.AddTransient <ServerExceptionsGrpcClientInterceptor>();
     services.AddSingleton <GlobalizationLocalizationGrpcClientInterceptor>();
     services.AddSingleton <ClientUriGrpcClientInterceptor>();
     services.AddTransient <CancellationWorkaroundGrpcClientInterceptor>();
     services.AddTransient <GrpcWebHandler>(provider => new GrpcWebHandler(GrpcWebMode.GrpcWeb, new HttpClientHandler()));
     services.AddSingleton <ClientFactory>(ClientFactory.Create(BinderConfiguration.Create(marshallerFactories: new[] { ProtoBufMarshallerFactory.Create(RuntimeTypeModel.Create().RegisterApplicationContracts(assemblyToScanForDataContracts)) }, binder: new ProtoBufServiceBinder())));
 }
Exemplo n.º 5
0
        // This method gets called by the runtime. Use this method to add services to the container.
        // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddCodeFirstGrpc(config =>
            {
                config.ResponseCompressionLevel = System.IO.Compression.CompressionLevel.Optimal;
            });
            services.TryAddSingleton(BinderConfiguration.Create(binder: new ServiceBinderWithServiceResolutionFromServiceCollection(services)));
            services.AddCodeFirstGrpcReflection();

            services.AddAuthentication(FakeAuthHandler.SchemeName)
            .AddScheme <FakeAuthOptions, FakeAuthHandler>(FakeAuthHandler.SchemeName, options => options.AlwaysAuthenticate = true);
            services.AddAuthorization();
            services.AddSingleton <ICounter, MyCounter>();
        }
        public static void AddGrpcServerInfrastructure(
            this IServiceCollection services,
            Assembly assemblyToScanForDataContracts,
            Action <GrpcServiceOptions> configureOptions = null)
        {
            services.AddSingleton <GlobalizationLocalizationGrpcServerInterceptor>();
            services.AddSingleton <ServerExceptionsGrpcServerInterceptor>();
            services.AddSingleton(BinderConfiguration.Create(marshallerFactories: new[] { ProtoBufMarshallerFactory.Create(RuntimeTypeModel.Create().RegisterApplicationContracts(assemblyToScanForDataContracts)) }, binder: new ServiceBinderWithServiceResolutionFromServiceCollection(services)));

            services.AddCodeFirstGrpc(options =>
            {
                options.Interceptors.Add <GlobalizationLocalizationGrpcServerInterceptor>();
                options.Interceptors.Add <ServerExceptionsGrpcServerInterceptor>();
                options.ResponseCompressionLevel = System.IO.Compression.CompressionLevel.Optimal;

                configureOptions?.Invoke(options);
            });
        }
Exemplo n.º 7
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.ConfigureForWebServer(configuration);

            services.AddSingleton <IHttpContextAccessor, HttpContextAccessor>();

            services.AddDatabaseDeveloperPageExceptionFilter();

            services.AddOptions();

            services.AddCustomizedMailing(configuration);

            // SmtpExceptionMonitoring to [email protected]
            services.AddExceptionMonitoring(configuration);

            // Application Insights
            services.AddApplicationInsightsTelemetry(configuration);
            services.AddSingleton <ITelemetryInitializer, GrpcRequestStatusTelemetryInitializer>();
            services.AddSingleton <ITelemetryInitializer, EnrichmentTelemetryInitializer>();
            services.ConfigureTelemetryModule <DependencyTrackingTelemetryModule>((module, o) => { module.EnableSqlCommandTextInstrumentation = true; });

            services.AddCustomizedAuth(configuration);

            // server-side UI
            services.AddControllersWithViews();
            services.AddRazorPages();

            // gRPC
            services.AddSingleton <ServerExceptionsGrpcServerInterceptor>();
            services.AddSingleton(BinderConfiguration.Create(marshallerFactories: new[] { ProtoBufMarshallerFactory.Create(RuntimeTypeModel.Default.RegisterApplicationContracts()) }, binder: new ServiceBinderWithServiceResolutionFromServiceCollection(services)));
            services.AddCodeFirstGrpc(config =>
            {
                config.Interceptors.Add <ServerExceptionsGrpcServerInterceptor>();
                config.ResponseCompressionLevel = System.IO.Compression.CompressionLevel.Optimal;
            });
        }
 static MetadataServiceSerializer()
 {
     TypeModel           = CreateRuntimeTypeModel();
     BinderConfiguration = BinderConfiguration.Create(new[] { ProtoBufMarshallerFactory.Create(TypeModel, ProtoBufMarshallerFactory.Options.None) });
     ClientFactory       = ClientFactory.Create(BinderConfiguration);
 }
 private static BinderConfiguration CreateBinderConfiguration()
 {
     return(BinderConfiguration.Create(new[] { ProtoBufMarshallerFactory.Create(CreateModel(), ProtoBufMarshallerFactory.Options.None) }));
 }
 public static BinderConfiguration CreateBinderConfiguration(ServiceBinder?serviceBinder = null) =>
 BinderConfiguration.Create(new[] { ProtoBufMarshallerFactory.Create(ProtoBufSerializer.TypeModel) }, serviceBinder);