public void InitializesCorrectlyWithStringScope()
        {
            ServiceInfo sInfo = new ServiceInfo(typeof (IServiceLoaderService), typeof (ServiceLoaderService), "Global");

            Assert.AreEqual(typeof (IServiceLoaderService), sInfo.RegisterAs);
            Assert.AreEqual(typeof (ServiceLoaderService), sInfo.Type);
            Assert.AreEqual(ServiceScope.Global, sInfo.Scope);
        }
        public void InitializesCorrectlyWithEnumScope()
        {
            ServiceInfo sInfo =
                new ServiceInfo(typeof (IServiceLoaderService), typeof (ServiceLoaderService), ServiceScope.Module);

            Assert.AreEqual(typeof (IServiceLoaderService), sInfo.RegisterAs);
            Assert.AreEqual(typeof (ServiceLoaderService), sInfo.Type);
            Assert.AreEqual(ServiceScope.Module, sInfo.Scope);
        }
        public void RegisteredGlobalServiceInstanceGetsAddedToGlobalServicesCollection()
        {
            CompositionContainer rootContainer = new TestableRootCompositionContainer();
            CompositionContainer childContainer = rootContainer.Containers.AddNew<CompositionContainer>();
            ServiceInfo info = new ServiceInfo(typeof (IMockService), typeof (MockService), ServiceScope.Global);
            ServiceLoaderService serviceLoader = new ServiceLoaderService();

            serviceLoader.Load(childContainer, info);

            Assert.IsTrue(rootContainer.Services.Contains(typeof (IMockService)));
            Assert.AreEqual(typeof (MockService), rootContainer.Services.Get<IMockService>(true).GetType());
        }
        private void LoadService(CompositionContainer container, ServiceInfo service)
        {
            IServiceCollection serviceCollection;

            switch (service.Scope)
            {
                case ServiceScope.Global:
                    serviceCollection = container.RootContainer.Services;
                    break;

                case ServiceScope.Module:
                    serviceCollection = container.Services;
                    break;

                default:
                    serviceCollection = container.RootContainer.Services;
                    break;
            }

            serviceCollection.AddNew(service.Type, service.RegisterAs);
        }
 public void ShouldFailIfScopeNotExists()
 {
     ServiceInfo sInfo = new ServiceInfo(typeof (IServiceLoaderService), typeof (ServiceLoaderService), "Any");
 }
 private void LoadServices(CompositionContainer container, ServiceInfo[] services)
 {
     foreach (ServiceInfo service in services)
     {
         LoadService(container, service);
     }
 }