Exemplo n.º 1
0
 public ApplicationDefinition()
 {
     Services     = new ServiceDefinitionCollection(this);
     Enumerations = new EnumerationDefinitionCollection(this);
     Models       = new ModelDefinitionCollection(this);
     Databases    = new DatabaseDefinitionCollection(this);
 }
        /// <summary>
        /// Adds a code-first service to the available services
        /// </summary>
        public static int AddCodeFirst <TService>(this ServiceDefinitionCollection services, TService service, BinderConfiguration?binderConfiguration = null)
            where TService : class
        {
            var builder = ServerServiceDefinition.CreateBuilder();
            int count   = Binder.Instance.Bind <TService>(builder, binderConfiguration, service);

            services.Add(builder.Build());
            return(count);
        }
        public void BindServices(ServiceDefinitionCollection services)
        {
            var textWriterAdapter = new TextWriterAdapter(
                _startupContext,
                Interfaces.Logging.Severity.Info,
                component: nameof(ContentMetadataService),
                operation: "Grpc");

            services.AddCodeFirst <IContentMetadataService>(this, MetadataServiceSerializer.BinderConfiguration, textWriterAdapter);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Create a new server.
 /// </summary>
 /// <param name="options">Channel options.</param>
 public Server(IEnumerable <ChannelOption> options = null)
 {
     this.serviceDefinitions = new ServiceDefinitionCollection(this);
     this.ports       = new ServerPortCollection(this);
     this.environment = GrpcEnvironment.AddRef();
     this.options     = options != null ? new List <ChannelOption>(options) : new List <ChannelOption>();
     using (var channelArgs = ChannelOptions.CreateChannelArgs(this.options))
     {
         this.handle = ServerSafeHandle.NewServer(environment.CompletionQueue, channelArgs);
     }
 }
Exemplo n.º 5
0
        public static IEnumerable <string> GetServicesName(this ServiceDefinitionCollection serviceDefinitionCollection)
        {
            var result = new List <string>();

            foreach (var srv in serviceDefinitionCollection)
            {
                var sd   = new ServiceDescriptor(typeof(ServerServiceDefinition), srv);
                var info = srv.GetType().GetField("callHandlers", BindingFlags.Instance | BindingFlags.NonPublic);


                foreach (var s in (IEnumerable)info.GetValue(srv))
                {
                    var kv = s.ToString().Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                    result.Add(kv[1]);
                    break;
                }
            }
            return(result);
        }
        private static int AddCodeFirstImpl(ServiceDefinitionCollection services, object service, Type serviceType,
                                            BinderConfiguration?binderConfiguration,
                                            TextWriter?log,
                                            IEnumerable <Interceptor>?interceptors)
        {
            var builder = ServerServiceDefinition.CreateBuilder();
            int count   = Binder.Create(log).Bind(builder, serviceType, binderConfiguration, service);
            var serverServiceDefinition = builder.Build();

            if (interceptors is object)
            {
                foreach (var interceptor in interceptors)
                {
                    serverServiceDefinition = serverServiceDefinition.Intercept(interceptor);
                }
            }

            services.Add(serverServiceDefinition);
            return(count);
        }
        /// <summary>
        /// Adds a code-first service to the available services
        /// </summary>
        public static int AddCodeFirst <TService>(this ServiceDefinitionCollection services, TService service,
                                                  BinderConfiguration?binderConfiguration = null,
                                                  TextWriter?log = null,
                                                  IEnumerable <Interceptor>?interceptors = null)
            where TService : class
        {
            var builder = ServerServiceDefinition.CreateBuilder();
            int count   = Binder.Create(log).Bind <TService>(builder, binderConfiguration, service);
            var serverServiceDefinition = builder.Build();

            if (interceptors is object)
            {
                foreach (var interceptor in interceptors)
                {
                    serverServiceDefinition = serverServiceDefinition.Intercept(interceptor);
                }
            }

            services.Add(serverServiceDefinition);
            return(count);
        }
Exemplo n.º 8
0
 public Server()
 {
     m_Ports             = new List <ServerPort>();
     m_Services          = new List <ServerServiceDefinition>();
     m_ServiceCollection = new ServiceDefinitionCollection(this);
 }
 /// <summary>
 /// Adds a code-first service to the available services
 /// </summary>
 public static int AddCodeFirst <TService>(ServiceDefinitionCollection services, TService service,
                                           BinderConfiguration?binderConfiguration,
                                           TextWriter?log)
     where TService : class // forwarded to preserve older API
 => AddCodeFirst <TService>(services, service, binderConfiguration, log, null);
 /// <summary>
 /// Adds a code-first service to the available services
 /// </summary>
 public static int AddCodeFirst(this ServiceDefinitionCollection services, object service,
                                BinderConfiguration?binderConfiguration = null,
                                TextWriter?log = null,
                                IEnumerable <Interceptor>?interceptors = null)
 => AddCodeFirstImpl(services, service, service?.GetType() ?? throw new ArgumentNullException(nameof(service)), binderConfiguration, log, interceptors);
 /// <summary>
 /// Adds a code-first service to the available services
 /// </summary>
 public static int AddCodeFirst <TService>(this ServiceDefinitionCollection services, TService service,
                                           BinderConfiguration?binderConfiguration = null,
                                           TextWriter?log = null,
                                           IEnumerable <Interceptor>?interceptors = null)
     where TService : class
 => AddCodeFirstImpl(services, service, typeof(TService), binderConfiguration, log, interceptors);