示例#1
0
 /// <summary>
 /// Inject dependent third-party components
 /// </summary>
 /// <param name="builder"></param>
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.Register(provider =>
     {
         IServiceExecutor serviceExecutor = null;
         if (provider.IsRegistered(typeof(IServiceExecutor)))
         {
             serviceExecutor = provider.Resolve <IServiceExecutor>();
         }
         return(new ThriftTransportClientFactory(provider.Resolve <ITransportMessageCodecFactory>(),
                                                 provider.Resolve <IHealthCheckService>(),
                                                 provider.Resolve <ILogger <ThriftTransportClientFactory> >(),
                                                 serviceExecutor));
     }).As(typeof(ITransportClientFactory)).SingleInstance();
     builder.Register(provider =>
     {
         return(new DefaultThriftServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultThriftServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(IThriftServiceEntryProvider)).SingleInstance();
     if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.Tcp ||
         AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
     {
         RegisterDefaultProtocol(builder);
     }
 }
示例#2
0
        private static void RegisterHttpProtocol(ContainerBuilderWrapper builder)
        {
            builder.Register(provider =>
            {
                return(new KestrelHttpMessageListener(
                           provider.Resolve <ILogger <KestrelHttpMessageListener> >(),
                           provider.Resolve <ISerializer <string> >(),
                           provider.Resolve <IServiceEngineLifetime>(),
                           provider.Resolve <IModuleProvider>(),
                           provider.Resolve <IServiceRouteProvider>(),
                           provider.Resolve <CPlatformContainer>()

                           ));
            }).SingleInstance();
            builder.Register(provider =>
            {
                var executor        = provider.ResolveKeyed <IServiceExecutor>(CommunicationProtocol.Http.ToString());
                var messageListener = provider.Resolve <KestrelHttpMessageListener>();
                return(new HttpServiceHost(async endPoint =>
                {
                    await messageListener.StartAsync(endPoint);
                    return messageListener;
                }, executor, messageListener));
            }).As <IServiceHost>();
        }
示例#3
0
 private SkywalkingModule AddSampling(ContainerBuilderWrapper builder)
 {
     builder.RegisterType <SimpleCountSamplingInterceptor>().SingleInstance();
     builder.Register <ISamplingInterceptor>(p => p.Resolve <SimpleCountSamplingInterceptor>()).SingleInstance();
     builder.Register <IExecutionService>(p => p.Resolve <SimpleCountSamplingInterceptor>()).SingleInstance();
     builder.RegisterType <RandomSamplingInterceptor>().As <ISamplingInterceptor>().SingleInstance();
     return(this);
 }
示例#4
0
        private static void RegisterConfigInstance(ContainerBuilderWrapper builder)
        {
            var cacheWrapperSetting = AppConfig.Configuration.Get <CachingProvider>();
            var bingingSettings     = cacheWrapperSetting.CachingSettings;

            try
            {
                var types =
                    typeof(AppConfig)
                    .Assembly.GetTypes()
                    .Where(
                        p => p.GetTypeInfo().GetInterface("ICacheProvider") != null);
                foreach (var t in types)
                {
                    foreach (var setting in bingingSettings)
                    {
                        var properties = setting.Properties;
                        var args       = properties.Select(p => GetTypedPropertyValue(p)).ToArray();
                        ;
                        var maps =
                            properties.Select(p => p.Maps)
                            .FirstOrDefault(p => p != null && p.Any());
                        var type = Type.GetType(setting.Class, true);
                        builder.Register(p => Activator.CreateInstance(type, args)).Named(setting.Id, type)
                        .SingleInstance();

                        if (maps == null)
                        {
                            continue;
                        }
                        if (!maps.Any())
                        {
                            continue;
                        }
                        foreach (
                            var mapsetting in
                            maps.Where(mapsetting =>
                                       t.Name.StartsWith(mapsetting.Name, StringComparison.CurrentCultureIgnoreCase)))
                        {
                            builder.Register(p => Activator.CreateInstance(t, setting.Id))
                            .Named(string.Format("{0}.{1}", setting.Id, mapsetting.Name), typeof(ICacheProvider))
                            .SingleInstance();
                        }
                    }

                    var attribute = t.GetTypeInfo().GetCustomAttribute <IdentifyCacheAttribute>();
                    if (attribute != null)
                    {
                        builder.Register(p => Activator.CreateInstance(t))
                        .Named(attribute.Name.ToString(), typeof(ICacheProvider)).SingleInstance();
                    }
                }
            }
            catch
            {
            }
        }
示例#5
0
        /// <summary>
        /// Inject dependent third-party components
        /// </summary>
        /// <param name="builder"></param>
        protected override void RegisterBuilder(ContainerBuilderWrapper builder)
        {
            var options = new WebSocketOptions();
            var section = AppConfig.GetSection("WebSocket");

            if (section.Exists())
            {
                options = section.Get <WebSocketOptions>();
            }
            base.RegisterBuilder(builder);
            builder.Register(provider =>
            {
                return(new DefaultWSServiceEntryProvider(
                           provider.Resolve <IServiceEntryProvider>(),
                           provider.Resolve <ILogger <DefaultWSServiceEntryProvider> >(),
                           provider.Resolve <CPlatformContainer>(),
                           options
                           ));
            }).As(typeof(IWSServiceEntryProvider)).SingleInstance();
            if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.WS)
            {
                RegisterDefaultProtocol(builder, options);
            }
            else if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
            {
                RegisterWSProtocol(builder, options);
            }
        }
示例#6
0
        /// <summary>
        /// Inject dependent third-party components
        /// </summary>
        /// <param name="builder"></param>
        protected override void RegisterBuilder(ContainerBuilderWrapper builder)
        {
            base.RegisterBuilder(builder);
            var section = CPlatform.AppConfig.GetSection("Dns");

            if (section.Exists())
            {
                AppConfig.DnsOption = section.Get <DnsOption>();
            }
            builder.Register(provider =>
            {
                return(new DefaultDnsServiceEntryProvider(
                           provider.Resolve <IServiceEntryProvider>(),
                           provider.Resolve <ILogger <DefaultDnsServiceEntryProvider> >(),
                           provider.Resolve <CPlatformContainer>()
                           ));
            }).As(typeof(IDnsServiceEntryProvider)).SingleInstance();
            builder.RegisterType(typeof(DnsServiceExecutor)).As(typeof(IServiceExecutor))
            .Named <IServiceExecutor>(CommunicationProtocol.Dns.ToString()).SingleInstance();
            if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.Dns)
            {
                RegisterDefaultProtocol(builder);
            }
            else if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
            {
                RegisterHttpProtocol(builder);
            }
        }
 public EventBusRabbitMQModule UseRabbitMQTransport(ContainerBuilderWrapper builder)
 {
     builder.RegisterType(typeof(Implementation.EventBusRabbitMQ)).As(typeof(IEventBus)).SingleInstance();
     builder.RegisterType(typeof(DefaultConsumeConfigurator)).As(typeof(IConsumeConfigurator)).SingleInstance();
     builder.RegisterType(typeof(InMemoryEventBusSubscriptionsManager)).As(typeof(IEventBusSubscriptionsManager)).SingleInstance();
     builder.Register(provider =>
     {
         var logger            = provider.Resolve <ILogger <DefaultRabbitMQPersistentConnection> >();
         EventBusOption option = new EventBusOption();
         var section           = CPlatform.AppConfig.GetSection("EventBus");
         if (section.Exists())
         {
             option = section.Get <EventBusOption>();
         }
         else if (AppConfig.Configuration != null)
         {
             option = AppConfig.Configuration.Get <EventBusOption>();
         }
         var factory = new ConnectionFactory()
         {
             HostName    = option.EventBusConnection,
             UserName    = option.EventBusUserName,
             Password    = option.EventBusPassword,
             VirtualHost = option.VirtualHost,
             Port        = int.Parse(option.Port),
         };
         factory.RequestedHeartbeat = 60;
         AppConfig.BrokerName       = option.BrokerName;
         AppConfig.MessageTTL       = option.MessageTTL;
         AppConfig.RetryCount       = option.RetryCount;
         AppConfig.FailCount        = option.FailCount;
         return(new DefaultRabbitMQPersistentConnection(factory, logger));
     }).As <IRabbitMQPersistentConnection>();
     return(this);
 }
示例#8
0
 /// <summary>
 /// 设置使用基于Consul的Watch机制
 /// </summary>
 /// <param name="builder"></param>
 /// <returns></returns>
 public ConsulModule UseConsulWatch(ContainerBuilderWrapper builder, ConfigInfo configInfo)
 {
     builder.Register(provider =>
     {
         return(new ClientWatchManager(provider.Resolve <ILogger <ClientWatchManager> >(), configInfo));
     }).As <IClientWatchManager>().SingleInstance();
     return(this);
 }
示例#9
0
 private void RegisterHttpFlvProtocol(ContainerBuilderWrapper builder, LiveStreamOption options)
 {
     builder.Register(provider =>
     {
         return(new HttpFlvMessageListener(provider.Resolve <ILogger <HttpFlvMessageListener> >(),
                                           provider.Resolve <IMediaStreamProvider>().GetMediaStream()
                                           ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <HttpFlvMessageListener>();
         return(new HttpFlvServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }));
     }).As <IServiceHost>();
 }
示例#10
0
 private static void RegisterWSProtocol(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DotNettyWSMessageListener(provider.Resolve <ILogger <DotNettyWSMessageListener> >(),
                                              provider.Resolve <IWSServiceEntryProvider>()
                                              ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <DotNettyWSMessageListener>();
         return(new WSServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }));
     }).As <IServiceHost>();
 }
示例#11
0
 private void RegisterDefaultProtocol(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DotNettyServerMessageListener(provider.Resolve <ILogger <DotNettyServerMessageListener> >(),
                                                  provider.Resolve <ITransportMessageCodecFactory>()));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var serviceExecutor = provider.ResolveKeyed <IServiceExecutor>(CommunicationProtocol.Tcp.ToString());
         var messageListener = provider.Resolve <DotNettyServerMessageListener>();
         return(new DefaultServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }, serviceExecutor));
     }).As <IServiceHost>();
 }
示例#12
0
 private static void RegisterDefaultProtocol(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DotNettyTcpServerMessageListener(provider.Resolve <ILogger <DotNettyTcpServerMessageListener> >(),
                                                     "default", new TcpServerProperties()
                                                     ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <DotNettyTcpServerMessageListener>();
         return(new TcpServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }));
     }).As <IServiceHost>();
 }
示例#13
0
 private static void RegisterHttpProtocol(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DefaultKestrelHttpMessageListener(
                    provider.Resolve <ILogger <DefaultKestrelHttpMessageListener> >()
                    ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <DefaultKestrelHttpMessageListener>();
         return(new HttpServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }, null));
     }).As <IServiceHost>();
 }
示例#14
0
 private static void RegisterMqttProtocol(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DotNettyMqttServerMessageListener(provider.Resolve <ILogger <DotNettyMqttServerMessageListener> >(),
                                                      provider.Resolve <IChannelService>(),
                                                      provider.Resolve <IMqttBehaviorProvider>()
                                                      ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <DotNettyMqttServerMessageListener>();
         return(new MqttServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }));
     }).As <IServiceHost>();
 }
示例#15
0
        /// <summary>
        /// Inject dependent third-party components
        /// </summary>
        /// <param name="builder"></param>
        protected override void RegisterBuilder(ContainerBuilderWrapper builder)
        {
            base.RegisterBuilder(builder);
            builder.RegisterType <MqttTransportDiagnosticProcessor>().As <ITracingDiagnosticProcessor>().SingleInstance();
            builder.RegisterType(typeof(DefaultMqttServiceFactory)).As(typeof(IMqttServiceFactory)).SingleInstance();
            builder.RegisterType(typeof(DefaultMqttBrokerEntryManager)).As(typeof(IMqttBrokerEntryManger)).SingleInstance();
            builder.RegisterType(typeof(MqttRemoteInvokeService)).As(typeof(IMqttRemoteInvokeService)).SingleInstance();
            builder.Register(provider =>
            {
                return(new WillService(
                           provider.Resolve <ILogger <WillService> >(),
                           provider.Resolve <CPlatformContainer>()
                           ));
            }).As <IWillService>().SingleInstance();
            builder.Register(provider =>
            {
                return(new MessagePushService(new SacnScheduled()));
            }).As <IMessagePushService>().SingleInstance();
            builder.RegisterType(typeof(ClientSessionService)).As(typeof(IClientSessionService)).SingleInstance();
            builder.Register(provider =>
            {
                return(new MqttChannelService(
                           provider.Resolve <IMessagePushService>(),
                           provider.Resolve <IClientSessionService>(),
                           provider.Resolve <ILogger <MqttChannelService> >(),
                           provider.Resolve <IWillService>(),
                           provider.Resolve <IMqttBrokerEntryManger>(),
                           provider.Resolve <IMqttRemoteInvokeService>(),
                           provider.Resolve <IServiceIdGenerator>()
                           ));
            }).As(typeof(IChannelService)).SingleInstance();
            builder.RegisterType(typeof(DefaultMqttBehaviorProvider)).As(typeof(IMqttBehaviorProvider)).SingleInstance();

            if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.Mqtt)
            {
                RegisterDefaultProtocol(builder);
            }
            else if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
            {
                RegisterMqttProtocol(builder);
            }
        }
示例#16
0
 private void RegisterRtmpProtocol(ContainerBuilderWrapper builder, LiveStreamOption options)
 {
     builder.Register(provider =>
     {
         return(new RtmpMessageListener(provider.Resolve <ILogger <RtmpMessageListener> >(),
                                        options.EnableLog? provider.Resolve <ILoggerFactory>() : new LoggerFactory(),
                                        provider.Resolve <IMediaStreamProvider>().GetMediaStream()
                                        ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <RtmpMessageListener>();
         var serviceExecutor = provider.ResolveNamed <IServiceExecutor>("Rtmp");
         return(new RtmpServiceHost(serviceExecutor, async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }));
     }).As <IServiceHost>();
 }
示例#17
0
 private static void RegisterDefaultProtocol(ContainerBuilderWrapper builder, WebSocketOptions options)
 {
     builder.Register(provider =>
     {
         return(new DefaultWSServerMessageListener(
                    provider.Resolve <ILogger <DefaultWSServerMessageListener> >(),
                    provider.Resolve <IWSServiceEntryProvider>(),
                    options
                    ));
     }).SingleInstance();
     builder.Register(provider =>
     {
         var messageListener = provider.Resolve <DefaultWSServerMessageListener>();
         return(new DefaultServiceHost(async endPoint =>
         {
             await messageListener.StartAsync(endPoint);
             return messageListener;
         }, null));
     }).As <IServiceHost>();
 }
示例#18
0
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.Register(provider =>
     {
         return(new DefaultBackgroundServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultBackgroundServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(IBackgroundServiceEntryProvider)).SingleInstance();
 }
示例#19
0
 /// <summary>
 /// Inject dependent third-party components
 /// </summary>
 /// <param name="builder"></param>
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.RegisterType <AsyncQueueSegmentDispatcher>().As <ISegmentDispatcher>().SingleInstance();
     builder.RegisterType <RegisterService>().As <IExecutionService>().SingleInstance();
     builder.RegisterType <PingService>().As <IExecutionService>().SingleInstance();
     builder.RegisterType <ServiceDiscoveryV5Service>().As <IExecutionService>().SingleInstance();
     builder.RegisterType <SegmentReportService>().As <IExecutionService>().SingleInstance();
     builder.RegisterType <InstrumentStartup>().As <IInstrumentStartup>().SingleInstance();
     builder.Register <IRuntimeEnvironment>(p => RuntimeEnvironment.Instance).SingleInstance();
     builder.RegisterType <TracingDiagnosticProcessorObserver>().SingleInstance();
     builder.RegisterType <ConfigAccessor>().As <IConfigAccessor>().SingleInstance();
     builder.RegisterType <ConfigurationFactory>().As <IConfigurationFactory>().SingleInstance();
     builder.RegisterType <HostingEnvironmentProvider>().As <IEnvironmentProvider>().SingleInstance();
     AddTracing(builder).AddSampling(builder).AddGrpcTransport(builder);
 }
示例#20
0
        /// <summary>
        /// 注册服务
        /// </summary>
        /// <param name="builder">构建器包装</param>
        protected override void ConfigureContainer(ContainerBuilderWrapper builder)
        {
            builder.RegisterType <FaultTolerantProvider>().As <IFaultTolerantProvider>().SingleInstance();
            builder.RegisterType <DefaultHealthCheckService>().As <IHealthCheckService>().SingleInstance();
            builder.RegisterType <ServiceDiscoveryProvider>().As <IServiceDiscoveryProvider>().SingleInstance();
            builder.RegisterType <ServiceRegisterProvider>().As <IServiceRegisterProvider>().SingleInstance();
            builder.RegisterType <ServiceSubscribeProvider>().As <IServiceSubscribeProvider>().SingleInstance();
            builder.RegisterType <ServiceCacheProvider>().As <IServiceCacheProvider>().SingleInstance();
            builder.RegisterType <ServicePartProvider>().As <IServicePartProvider>().SingleInstance();

            builder.Register(provider =>
            {
                var serviceProxyProvider = provider.Resolve <IServiceProxyProvider>();
                var serviceRouteProvider = provider.Resolve <IServiceRouteProvider>();
                var serviceProvider      = provider.Resolve <CPlatformContainer>();
                return(new AuthorizationServerProvider(serviceProxyProvider, serviceRouteProvider, serviceProvider));
            }).As <IAuthorizationServerProvider>().SingleInstance();
        }
示例#21
0
 /// <summary>
 /// 注册服务
 /// </summary>
 /// <param name="builder">构建器包装</param>
 protected override void ConfigureContainer(ContainerBuilderWrapper builder)
 {
     builder.Register(provider =>
     {
         return(new DefaultGrpcServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultGrpcServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(IGrpcServiceEntryProvider)).SingleInstance();
     if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.WS)
     {
         RegisterDefaultProtocol(builder);
     }
     else if (AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
     {
         RegisterGrpcProtocol(builder);
     }
 }
示例#22
0
 /// <summary>
 /// Inject dependent third-party components
 /// </summary>
 /// <param name="builder"></param>
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.Register(provider =>
     {
         return(new DefaultUdpServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultUdpServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(IUdpServiceEntryProvider)).SingleInstance();
     builder.RegisterType(typeof(UdpServiceExecutor)).As(typeof(IServiceExecutor))
     .Named <IServiceExecutor>(CommunicationProtocol.Udp.ToString()).SingleInstance();
     if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.Dns)
     {
         RegisterDefaultProtocol(builder);
     }
     else if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
     {
         RegisterUdpProtocol(builder);
     }
 }
示例#23
0
 /// <summary>
 /// Inject dependent third-party components
 /// </summary>
 /// <param name="builder"></param>
 protected override void RegisterBuilder(ContainerBuilderWrapper builder)
 {
     base.RegisterBuilder(builder);
     builder.Register(provider =>
     {
         return(new DefaultTcpServiceEntryProvider(
                    provider.Resolve <IServiceEntryProvider>(),
                    provider.Resolve <ILogger <DefaultTcpServiceEntryProvider> >(),
                    provider.Resolve <CPlatformContainer>()
                    ));
     }).As(typeof(ITcpServiceEntryProvider)).SingleInstance();
     builder.RegisterType(typeof(DefaultDeviceProvider)).As(typeof(IDeviceProvider)).SingleInstance();
     builder.RegisterType(typeof(DefaultTcpServiceEntryProvider)).As(typeof(ITcpServiceEntryProvider)).SingleInstance();
     builder.RegisterType(typeof(TcpNetworkProvider)).As <INetworkProvider <TcpServerProperties> >().SingleInstance();
     if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.Tcp)
     {
         RegisterDefaultProtocol(builder);
     }
     else if (CPlatform.AppConfig.ServerOptions.Protocol == CommunicationProtocol.None)
     {
         RegisterTcpProtocol(builder);
     }
 }