コード例 #1
0
        /// <summary>
        /// Creates the default service container.
        /// </summary>
        /// <param name="userServiceProvider">The user service provider.</param>
        /// <param name="appInstance">The app instance.</param>
        /// <returns></returns>
        protected virtual IMonoRailContainer CreateDefaultMonoRailContainer(IServiceProviderEx userServiceProvider,
                                                                            HttpApplication appInstance)
        {
            var container = new DefaultMonoRailContainer(userServiceProvider);

            container.UseServicesFromParent();
            container.InstallPrimordialServices();
            container.Configure(Configuration);

            FireContainerCreated(appInstance, container);

            // Too dependent on Http and MR surroundings services to be moved to Container class
            if (!container.HasService <IServerUtility>())
            {
                container.AddService <IServerUtility>(new ServerUtilityAdapter(appInstance.Context.Server));
            }
            if (!container.HasService <IRoutingEngine>())
            {
                container.AddService <IRoutingEngine>(RoutingModuleEx.Engine);
            }

            container.InstallMissingServices();
            container.StartExtensionManager();

            FireContainerInitialized(appInstance, container);

            return(container);
        }
コード例 #2
0
        public void CacheOverrideTest()
        {
            var containerType = _defaultMonoRailContainer.GetType();

            foreach (var serviceType in _serviceTypes)
            {
                // check if it was registered
                Assert.IsTrue(_defaultMonoRailContainer.HasService(serviceType), string.Format("expected registered service of type {0}", serviceType));

                // get the name of the service property by stripping the I
                var propertyName = serviceType.Name.Substring(1);

                // get the service via the property
                var propertyInfo = containerType.GetProperty(propertyName);
                Assert.IsNotNull(propertyInfo, string.Format("Property {0} not found on DefaultMonoRailsContainer", propertyName));

                var serviceInstance = propertyInfo.GetValue(_defaultMonoRailContainer, null);
                Assert.IsNotNull(serviceInstance, string.Format("Expected a registered service of type {0}", serviceType));

                // check if the underlying hastable has the same value as the property
                Assert.AreSame(serviceInstance, _defaultMonoRailContainer.GetService(serviceType));

                // generate a stub and call the setter
                var stub = MockRepository.GenerateStub(serviceType);
                propertyInfo.SetValue(_defaultMonoRailContainer, stub, null);

                // re-get the value
                serviceInstance = propertyInfo.GetValue(_defaultMonoRailContainer, null);

                // compare to the stub to make sure the cache has been overridden
                Assert.AreSame(serviceInstance, _defaultMonoRailContainer.GetService(serviceType), string.Format("Cache bug found for service {0}", serviceType));
            }
        }
コード例 #3
0
        public void UseServicesFromParent_WhenParentContainsRoutingEngineService_ServiceAddedToMonoRailContainer()
        {
            var engine = MockRepository.GenerateStub <IRoutingEngine>();
            var parent = MockRepository.GenerateStub <IServiceProvider>();

            parent.Stub(stub => stub.GetService(typeof(IRoutingEngine))).Return(engine);

            var container = new DefaultMonoRailContainer(parent);

            container.UseServicesFromParent();

            Assert.True(container.HasService <IRoutingEngine>());
        }
コード例 #4
0
		public void UseServicesFromParent_WhenParentContainsRoutingEngineService_ServiceAddedToMonoRailContainer()
		{
			IRoutingEngine engine = MockRepository.GenerateStub<IRoutingEngine>();
			IServiceProvider parent = MockRepository.GenerateStub<IServiceProvider>();

			parent.Stub(stub => stub.GetService(typeof(IRoutingEngine))).Return(engine);

			DefaultMonoRailContainer container = new DefaultMonoRailContainer(parent);
			container.UseServicesFromParent();

			Assert.True(container.HasService<IRoutingEngine>());
		}