public void UnityServiceHost_Should_Use_Rest_GreetingService()
		{
			// Arrange
			ServiceHost serviceHost = new UnityServiceHost<GreetingService>(_container);
			using (var serviceHelper = new InjectedServiceHelper<IGreetingService>
				(serviceHost, ServiceAddress, new WebHttpBinding()))
			{
				IGreetingService client = serviceHelper.Client;
				using ((IDisposable)client)
				{
					// Act
					string greeting = client.Greet("Tony");

					// Assert
					Assert.That(greeting, Is.StringMatching("Howdy Tony"));
				}
			}
		}
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // Change this to switch between containers
            ContainerType containerType;
            System.Console.WriteLine("Select container: Ninject {N}, SimpleInjector {S}, Unity {U}");
            ConsoleKey containerKey = System.Console.ReadKey(true).Key;
            System.Console.WriteLine(containerKey.ToString().ToUpper());
            switch (containerKey)
            {
                case ConsoleKey.N:
                    containerType = ContainerType.Ninject;
                    break;
                case ConsoleKey.S:
                    containerType = ContainerType.SimpleInjector;
                    break;
                case ConsoleKey.U:
                    containerType = ContainerType.Unity;
                    break;
                default:
                    System.Console.WriteLine("Invalid selection");
                    return;
            }

            System.Console.Title = "Greeting Service using " + containerType;

            // Create service host
            ServiceHost serviceHost;
            var serviceBaseAddress = new Uri("http://localhost:8000/GreetingService");
            switch (containerType)
            {
                case ContainerType.Ninject:
                    serviceHost = new NinjectServiceHost<GreetingService>
                        (CreateNinjectContainer(), serviceBaseAddress);
                    break;
                case ContainerType.SimpleInjector:
                    serviceHost = new SimpleInjectorServiceHost<GreetingService>
                        (CreateSimpleInjectorContainer(), serviceBaseAddress);
                    break;
                case ContainerType.Unity:
                    serviceHost = new UnityServiceHost<GreetingService>
                        (CreateUnityContainer(), serviceBaseAddress);
                    break;
                default:
                    System.Console.WriteLine("Unsupported container: " + containerType);
                    return;
            }

            // Start service host
            using (serviceHost)
            {
                serviceHost.Open();
                System.Console.WriteLine("Endpoints:");
                foreach (var endpoint in serviceHost.Description.Endpoints)
                {
                    System.Console.WriteLine("{0}: {1}",
                        endpoint.Binding.Name, endpoint.Address);
                }
                System.Console.WriteLine();
                System.Console.WriteLine("Greeting service is using {0}.\nPress Enter to exit.",
                    containerType);
                System.Console.ReadLine();
            }
        }