/// <summary> /// This method is invoked right before InitRecursive() is called for this Panel and /// ensures, that dependencies get injected on child controls before their Init event is raised. /// </summary> protected virtual void OnPreInitRecursive(EventArgs e) { if (!_suppressDependencyInjection && _defaultApplicationContext == null) { // obtain appContext of the closed parent template (.ascx/.aspx) control IApplicationContext appCtx = WebApplicationContext.GetContext(this.TemplateSourceDirectory.TrimEnd('/') + "/"); // NOTE: _defaultApplicationContext will be set during DI! WebDependencyInjectionUtils.InjectDependenciesRecursive(appCtx, this); } }
/// <summary> /// Aquires an ApplicationContext according to a Control's TemplateSourceDirectory /// </summary> /// <returns>if availabe, the control's IApplicationContext instance - defaultContext otherwise</returns> private static IApplicationContext GetControlApplicationContext(IApplicationContext defaultContext, Control control) { // use control's directory for resolving context string srcDir = control.TemplateSourceDirectory; if (StringUtils.HasLength(srcDir)) { if (!srcDir.EndsWith("/")) { srcDir += "/"; } return(WebApplicationContext.GetContext(srcDir)); } else { return(defaultContext); } }
/// <summary> /// Retrieves instance of the page from Spring web application context. /// </summary> /// <param name="context">current HttpContext</param> /// <param name="requestType">type of HTTP request (GET, POST, etc.)</param> /// <param name="url">requested page URL</param> /// <param name="path">translated server path for the page</param> /// <returns>instance of the configured page object</returns> IHttpHandler IHttpHandlerFactory.GetHandler(HttpContext context, string requestType, string url, string path) { new AspNetHostingPermission(AspNetHostingPermissionLevel.Minimal).Demand(); IConfigurableApplicationContext appContext = WebApplicationContext.GetContext(url) as IConfigurableApplicationContext; if (appContext == null) { throw new InvalidOperationException( "Implementations of IApplicationContext must also implement IConfigurableApplicationContext"); } string appRelativeVirtualPath = WebUtils.GetAppRelativePath(url); AbstractHandlerFactory.NamedObjectDefinition nod = AbstractHandlerFactory.FindWebObjectDefinition(appRelativeVirtualPath, appContext.ObjectFactory); Type serviceType = null; if (nod != null) { #if !MONO if (appContext.IsTypeMatch(nod.Name, typeof(WebServiceExporter))) { WebServiceExporter wse = (WebServiceExporter)appContext.GetObject(nod.Name); serviceType = wse.GetExportedType(); } else { serviceType = appContext.GetType(nod.Name); // check if the type defines a Web Service object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true); if (wsAttribute.Length == 0) { serviceType = null; } } #else serviceType = appContext.GetType(nod.Name); // check if the type defines a Web Service object[] wsAttribute = serviceType.GetCustomAttributes(typeof(WebServiceAttribute), true); if (wsAttribute.Length == 0) { serviceType = null; } #endif } if (serviceType == null) { serviceType = WebServiceParser.GetCompiledType(url, context); } #if !MONO_2_0 return((IHttpHandler)CoreGetHandler.Invoke(this, new object[] { serviceType, context, context.Request, context.Response })); #else // find if the BuildManager already contains a cached value of the service type var buildCacheField = typeof(BuildManager).GetField("buildCache", BindingFlags.Static | BindingFlags.NonPublic); var buildCache = (IDictionary)buildCacheField.GetValue(null); if (!buildCache.Contains(appRelativeVirtualPath)) { // create new fake BuildManagerCacheItem wich represent the target type var buildManagerCacheItemType = Type.GetType("System.Web.Compilation.BuildManagerCacheItem, System.Web"); var cacheItemCtor = buildManagerCacheItemType.GetConstructor(new Type[] { typeof(Assembly), typeof(BuildProvider), typeof(CompilerResults) }); var buildProvider = new FakeBuildProvider(serviceType); var cacheItem = cacheItemCtor.Invoke(new object[] { serviceType.Assembly, buildProvider, null }); // store it in the BuildManager buildCache [appRelativeVirtualPath] = cacheItem; } // now that the target type is in the cache, let the default process continue return(base.GetHandler(context, requestType, url, path)); #endif }
/// <summary> /// Returns the unchecked, raw application context for the given virtual path. /// </summary> /// <param name="virtualPath">the virtual path to get the context for.</param> /// <returns>the context or null.</returns> /// <remarks> /// Subclasses may override this method to change the context source. /// By default, <see cref="WebApplicationContext.GetContext"/> is used for obtaining context instances. /// </remarks> protected virtual IApplicationContext GetContext(string virtualPath) { return(WebApplicationContext.GetContext(virtualPath)); }