Configure() public static méthode

Configures the instance and its modules.
When called, configures using the IApplicationContext instance provided in appContext and the templates available in ApplicationTemplate and ModuleTemplates.
public static Configure ( IConfigurableApplicationContext appContext, System.Web.HttpApplication app ) : void
appContext IConfigurableApplicationContext the application context instance to be used for resolving object references.
app System.Web.HttpApplication the instance to be configured.
Résultat void
Exemple #1
0
        public void ConfiguresApplicationAndModulesFromTemplate()
        {
            StaticApplicationContext appContext = CreateTestContext();

            HttpApplicationConfigurer h;
            RootObjectDefinition      rod;

            h   = new HttpApplicationConfigurer();
            rod = new RootObjectDefinition();
            rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject"));
            h.ApplicationTemplate = rod;
            rod = new RootObjectDefinition();
            rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject1"));
            h.ModuleTemplates.Add("TestModule1", rod);
            rod = new RootObjectDefinition();
            rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject2"));
            h.ModuleTemplates.Add("TestModule2", rod);

            TestModule m1 = new TestModule();
            TestModule m2 = new TestModule();

            TestApplication appObject = new TestApplication(new ModuleEntry[]
            {
                new ModuleEntry("TestModule1", m1)
                , new ModuleEntry("TestModule2", m2),
            });

            HttpApplicationConfigurer.Configure(appContext, appObject);
            // app configured
            Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject);
            // modules configured
            Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject);
            Assert.AreEqual(appContext.GetObject("testObject2"), m2.TestObject);
        }
Exemple #2
0
        public void ConfigureUsingXmlApplicationContext_CanMergePropertyValues()
        {
            XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerMergablePropertiesTests.xml", typeof(HttpApplicationConfigurerTests)));

            ParentHttpModule module = new ParentHttpModule();

            TestApplication appObject = new TestApplication(new ModuleEntry[]
            {
                new ModuleEntry("DirectoryServicesAuthentication", module)
            });

            HttpApplicationConfigurer.Configure(appContext, appObject);

            //base class property has carried through successfully
            Assert.Contains("GrandParentValue1", module.GrandParentProperty);

            //parent property values remain in the final instance
            Assert.Contains("ParentValue1", module.ParentProperty);
            Assert.Contains("ParentValue2", module.ParentProperty);
            Assert.Contains("ParentValue3", module.ParentProperty);
            Assert.Contains("ParentValue4", module.ParentProperty);

            //the new additional value has been merged into the property
            Assert.Contains("MergedValueToFind", module.ParentProperty);
        }
Exemple #3
0
        /// <summary>
        /// Registers this module for all events required by the Spring.Web framework
        /// </summary>
        public virtual void Init(HttpApplication app)
        {
            lock (typeof(WebSupportModule))
            {
                s_log.Debug("Initializing Application instance");
                if (!s_isInitialized)
                {
                    HttpModuleCollection modules = app.Modules;
                    foreach (string moduleKey in modules.AllKeys)
                    {
                        if (modules[moduleKey] is SessionStateModule)
                        {
                            HookSessionEvent((SessionStateModule)modules[moduleKey]);
                        }
                    }
                }
                s_isInitialized = true;

                // signal, that VirtualEnvironment is ready to accept
                // handler registrations for EndRequest and EndSession events
                VirtualEnvironment.SetInitialized();
            }

            app.PreRequestHandlerExecute += new EventHandler(OnConfigureHandler);
            app.EndRequest += new EventHandler(VirtualEnvironment.RaiseEndRequest);

#if NET_2_0
            // TODO: this is only a workaround to get us up & running in IIS7/integrated mode
            // We must review all code for relative virtual paths - they must be resolved to application-relative paths
            // during parsing of the object definitions
            bool hideRequestResponse = false;
            if (ContextHideRequestResponse != null)
            {
                hideRequestResponse = (bool)ContextHideRequestResponse.GetValue(app.Context);
                ContextHideRequestResponse.SetValue(app.Context, false);
            }
#endif
            try
            {
                // ensure context is instantiated
                IConfigurableApplicationContext appContext = WebApplicationContext.GetRootContext() as IConfigurableApplicationContext;
                // configure this app + it's module instances
                if (appContext == null)
                {
                    throw new InvalidOperationException("Implementations of IApplicationContext must also implement IConfigurableApplicationContext");
                }

                HttpApplicationConfigurer.Configure(appContext, app);
            }
            finally
            {
#if NET_2_0
                if (ContextHideRequestResponse != null)
                {
                    ContextHideRequestResponse.SetValue(app.Context, hideRequestResponse);
                }
#endif
            }
        }
        public void ThrowsOnUnapplicableModuleTemplate()
        {
            StaticApplicationContext appContext = CreateTestContext();

            HttpApplicationConfigurer h;
            RootObjectDefinition      rod;

            h   = new HttpApplicationConfigurer();
            rod = new RootObjectDefinition();
            rod.PropertyValues.Add("TestObject", new RuntimeObjectReference("testObject1"));
            h.ModuleTemplates.Add("TestModule1", rod);

            TestApplication appObject = new TestApplication(null);

            HttpApplicationConfigurer.Configure(appContext, appObject);
        }
        public void ConfigureUsingXmlApplicationContext()
        {
            XmlApplicationContext appContext = new XmlApplicationContext(false, ReadOnlyXmlTestResource.GetFilePath("HttpApplicationConfigurerTests.xml", typeof(HttpApplicationConfigurerTests)));

            TestModule m1 = new TestModule();
            TestModule m2 = new TestModule();

            TestApplication appObject = new TestApplication(new ModuleEntry[]
            {
                new ModuleEntry("TestModule1", m1)
                , new ModuleEntry("TestModule2", m2),
            });

            HttpApplicationConfigurer.Configure(appContext, appObject);
            // app configured
            Assert.AreEqual(appContext.GetObject("testObject"), appObject.TestObject);
            // modules configured
            Assert.AreEqual(appContext.GetObject("testObject1"), m1.TestObject);
            Assert.AreEqual(null, m2.TestObject);
        }