public AppSocketServer(
            string host, 
            int port, 
            int bufferSize,
            int maxConnect, 
            IObjectContainer container = null, 
            Action<IObjectContainer> action = null)
        {
            if (container == null)
            {
                container = new UnityObjectContainer();
            }

            AppSocketContainer.Ins.SetContainer(container);

            if (action != null)
            {
                action(AppSocketContainer.Ins.Container);
            }

            AppSocketContainer.Ins.RegisterInstance<IAppSocketServerConfig>(new AppSocketServerConfig()
            {
                Host = host,
                Port = port,
                BufferSize = bufferSize,
                MaxConnect = maxConnect
            }, IOCLife.Singleton);

            AppSocketContainer.Ins.RegisterAppSocketServerType<ILogger>((p, l) =>
            {
                p.RegisterType<ILogger, Log4NetLogger>(l);
            });

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketServerEvent>((p, l) =>
            {
                p.RegisterType<IAppSocketServerEvent, AppSocketServerEvent>(l);
            });

            _socketServerEvent = AppSocketContainer.Ins.Resolve<IAppSocketServerEvent>();
            _socketServerEvent.OnPreInit(AppSocketContainer.Ins);

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketAsyncEventArgsPool>((p, l) =>
            {
                p.RegisterType<IAppSocketAsyncEventArgsPool, DefaultAppSocketAsyncEventArgsPool>(l);
            });

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketSessionManager>((p, l) =>
            {
                p.RegisterType<IAppSocketSessionManager, DefaultAppSocketSessionManager>(l);
            });

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketBufferManager>((p, l) =>
            {
                p.RegisterType<IAppSocketBufferManager, DefaultAppSocketBufferManager>(l);
            });

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketProtocol>((p, l) =>
            {
                p.RegisterType<IAppSocketProtocol, DefaultAppSocketSplitProtocol>(l);
            });
            
            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketDataProcessor>((p, l) =>
            {
                p.RegisterType<IAppSocketDataProcessor, DefaultAppSocketDataProcessor>(l);
            });

            AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketClient>((p, l) =>
            {
                p.RegisterType<IAppSocketClient, DefaultAppTcpSocketClient>(l);
            }, IOCLife.Transient);

            _socketServerEvent.OnInit(AppSocketContainer.Ins);

            _logger = AppSocketContainer.Ins.Resolve<ILogger>();
            _serverConfig = AppSocketContainer.Ins.Resolve<IAppSocketServerConfig>();
            _socketBufferManager = AppSocketContainer.Ins.Resolve<IAppSocketBufferManager>();
            _socketAsyncEventArgsPool = AppSocketContainer.Ins.Resolve<IAppSocketAsyncEventArgsPool>();
            _socketDataProcessor = AppSocketContainer.Ins.Resolve<IAppSocketDataProcessor>();
            _socketSessionManager = AppSocketContainer.Ins.Resolve<IAppSocketSessionManager>();
        }
Exemple #2
0
        public AppSocketServer(IAppSocketConfig rootConfig, IAppSocketServerConfig serverConfig)
        {
            AppSocketContainer.Ins.SetContainer(new UnityObjectContainer());
            try
            {
                _rootConfig = rootConfig;
                _serverConfig = serverConfig;

                _logger = new Log4NetLogger();
                _logger.Init(_serverConfig.Logger);
                _autoReset = new AutoResetEvent(false);

                AppSocketContainer.Ins.RegisterInstance<ILogger>(_logger, IOCLife.Singleton);

                AppSocketContainer.Ins.RegisterInstance<IAppSocketConfig>(_rootConfig, IOCLife.Singleton);

                AppSocketContainer.Ins.RegisterInstance<IAppSocketServerConfig>(_serverConfig, IOCLife.Singleton);

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketServerEvent>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketServerEvent, AppSocketServerEvent>(l);
                });

                _socketServerEvent = AppSocketContainer.Ins.Resolve<IAppSocketServerEvent>();

                _socketServerEvent.OnPreInit(AppSocketContainer.Ins);

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketAsyncEventArgsPool>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketAsyncEventArgsPool, DefaultAppSocketAsyncEventArgsPool>(l);
                });

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketSessionManager>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketSessionManager, DefaultAppSocketSessionManager>(l);
                });

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketBufferManager>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketBufferManager, DefaultAppSocketBufferManager>(l);
                });

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketProtocol>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketProtocol, DefaultAppSocketSplitProtocol>(l);
                });

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketClient>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketClient, DefaultAppSocketClient>(l);
                }, IOCLife.Transient);

                AppSocketContainer.Ins.RegisterAppSocketServerType<IAppSocketDataProcessor>(_serverConfig, (p, l) =>
                {
                    p.RegisterType<IAppSocketDataProcessor, DefaultAppSocketDataProcessor>(l);
                }, IOCLife.Transient);

                _socketServerEvent.OnInit(AppSocketContainer.Ins);

                _logger = AppSocketContainer.Ins.Resolve<ILogger>();

                _logger.Init(_serverConfig.Logger);

                _socketBufferManager = AppSocketContainer.Ins.Resolve<IAppSocketBufferManager>();
                _socketAsyncEventArgsPool = AppSocketContainer.Ins.Resolve<IAppSocketAsyncEventArgsPool>();
                _socketDataProcessor = AppSocketContainer.Ins.Resolve<IAppSocketDataProcessor>();
                _socketSessionManager = AppSocketContainer.Ins.Resolve<IAppSocketSessionManager>();
            }
            catch (Exception ex)
            {
                _logger.Error(ex);
            }
        }