Exemple #1
0
        private static void CallTheServiceSynchronously()
        {
            IRequestDispatcher requestDispatcher = null;

            try
            {
                // NOTE: i'm using Agatha's IOC wrapper here directly... you could just as well resolve the IRequestDispatcher component
                // through _your_ container
                Console.WriteLine("Calling the service synchronously...");
                requestDispatcher = IoC.Container.Resolve <IRequestDispatcher>();

                Console.WriteLine("requesting a hello world... (synchronously)");
                requestDispatcher.Add(new HelloWorldRequest());
                Console.WriteLine("asking the server to reverse this string... (synchronously)");
                requestDispatcher.Add(new ReverseStringRequest {
                    StringToReverse = "asking the server to reverse this string"
                });

                Console.WriteLine(requestDispatcher.Get <HelloWorldResponse>().Message);
                Console.WriteLine(requestDispatcher.Get <ReverseStringResponse>().ReversedString);

                Console.WriteLine("Sending HelloWorldCommand");
                requestDispatcher.Send(new HelloWorldCommand());
            }
            finally
            {
                // not really necessary in this silly example, but it's recommended to release each RequestDispatcher instance once you're
                // done with it
                if (requestDispatcher != null)
                {
                    IoC.Container.Release(requestDispatcher);
                }
            }
        }
Exemple #2
0
        private static void CallTheServiceSynchronously()
        {
            IRequestDispatcher requestDispatcher = null;

            try
            {
                // NOTE: i'm using Agatha's IOC wrapper here directly... you could just as well resolve the IRequestDispatcher component
                // through _your_ container
                LogInfo("Calling the service synchronously...");
                requestDispatcher = IoC.Container.Resolve <IRequestDispatcher>();
                var response = requestDispatcher.Get <HelloWorldResponse>(new HelloWorldRequest {
                    Name = "World"
                });
                Console.WriteLine(response.Message);

                LogInfo("Sending HelloWorldCommand");
                requestDispatcher.Send(new HelloWorldCommand());
            }
            finally
            {
                // not really necessary in this silly example, but it's recommended to release each RequestDispatcher instance once you're
                // done with it
                if (requestDispatcher != null)
                {
                    IoC.Container.Release(requestDispatcher);
                }
            }
        }