Beispiel #1
0
        public void Start()
        {
            var container = new UnityObjectContainer();
            container.RegisterInstance(new Pig(), IOCLife.Singleton);
            var pig = container.Resolve<Pig>();
            pig.Name = "fdsafdsa";

            var pig2 = container.Resolve<Pig>();
            //var container = new UnityObjectContainer();
            //container.RegisterType<IAnimal, Pig>(LifeStyle.Transient);
            //var pig = container.Resolve<IAnimal>();
            //pig.ChangeName("fdsa");
            //var pig2 = container.Resolve<IAnimal>();
            //var pig=new  Pig();
            //pig.Name="xxoo";
            //container.RegisterInstance<Pig>(pig, LifeStyle.Transient);

            //var p = container.Resolve<Pig>();

            //p.Name = "ddd";
        }
        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>();
        }