コード例 #1
0
        public void ExternalConfigurationUsage()
        {
            WindsorContainer container = new WindsorContainer("../aop_castle_config.xml");

            container.AddFacility("aspectsharp", new AspectSharpFacility());

            // Logger implementation
            container.AddComponent("logger", typeof(ILogger), typeof(MemoryLogger));

            // AopAlliance interceptors
            container.AddComponent("log4netinterceptor", typeof(LoggerTraceInterceptor));

            // Protocol handlers
            container.AddComponent("protocolhandler.miranda",
                                   typeof(IProtocolHandler), typeof(MirandaProtocolHandler));
            container.AddComponent("protocolhandler.messenger",
                                   typeof(IProtocolHandler), typeof(MessengerProtocolHandler));

            // using...

            ILogger logger = (ILogger)container[typeof(ILogger)];

            Assert.AreEqual(0, logger.Contents.Length);

            IProtocolHandler handler = (IProtocolHandler)
                                       container["protocolhandler.miranda"];

            handler.Handle("contents");

            handler = (IProtocolHandler)container["protocolhandler.messenger"];
            handler.Handle("contents");

            Assert.AreEqual("Entering Handle Leaving Handle Entering Handle Leaving Handle ",
                            logger.Contents);
        }
コード例 #2
0
 private async Task StartReceiveOperations()
 {
     while (await Input.WaitToReadAsync())
     {
         while (Input.TryRead(out var operation))
         {
             await _protocol.Handle(new MessageContext(operation, Output));
         }
     }
 }