Web application context, taking the context definition files from the file system or from URLs. Treats resource paths as web resources, when using IApplicationContext.GetResource. Resource paths are considered relative to the virtual directory. Note: In case of multiple config locations, later object definitions will override ones defined in earlier loaded files. This can be leveraged to deliberately override certain object definitions via an extra XML file.
Inheritance: Spring.Context.Support.AbstractXmlApplicationContext
Exemplo n.º 1
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)
                        {
#if !NET_1_1
                            HookSessionEvent((SessionStateModule)modules[moduleKey]);
#else
                            HookSessionEvent11();
#endif
                        }
                    }
                }
                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
            }
        }
Exemplo n.º 2
0
        public void RunTestWithDI()
        {
//            LogManager.Adapter = new Common.Logging.Simple.TraceLoggerFactoryAdapter();

            DataView dv = CreateDataSource();
            using (TestWebContext wctx = new TestWebContext("/testpath", "testpage.aspx"))
            {
                IApplicationContext ctx = new WebApplicationContext();

                int runs = 1000;

                StopWatch watch = new StopWatch();
                using (watch.Start("Duration: {0}"))
                {
                    for (int i = 0; i < runs; i++)
                    {
                        DataGrid grid = new DataGrid();
                        Spring.Web.Support.WebDependencyInjectionUtils.InjectDependenciesRecursive(ctx, grid);
                        grid.DataSource = dv;
                        grid.DataBind();
                    }
                }

                using (watch.Start("Duration: {0}"))
                {
                    for (int i = 0; i < runs; i++)
                    {
                        DataGrid grid = new DataGrid();
                        grid.DataSource = dv;
                        grid.DataBind();
                        Spring.Web.Support.WebDependencyInjectionUtils.InjectDependenciesRecursive(ctx, grid);
                    }
                }
            }
        }