IRegisteredObject CheckIfExists(BareApplicationHost host, Type type, bool failIfExists) { IRegisteredObject ireg = host.GetObject(type); if (ireg == null) { return(null); } if (failIfExists) { throw new InvalidOperationException(String.Concat("Well known object of type '", type.Name, "' already exists in this domain.")); } return(ireg); }
public IRegisteredObject GetObject(string appId, Type type) { if (appId == null) { throw new ArgumentNullException("appId"); } if (type == null) { throw new ArgumentNullException("type"); } BareApplicationHost host = null; if (!id_to_host.ContainsKey(appId)) { return(null); } host = id_to_host [appId]; return(host.GetObject(type)); }
public IRegisteredObject CreateObject(string appId, Type type, string virtualPath, string physicalPath, bool failIfExists, bool throwOnError) { if (appId == null) { throw new ArgumentNullException("appId"); } if (!VirtualPathUtility.IsAbsolute(virtualPath)) { throw new ArgumentException("Relative path no allowed.", "virtualPath"); } if (String.IsNullOrEmpty(physicalPath)) { throw new ArgumentException("Cannot be null or empty", "physicalPath"); } // 'type' is not checked. If it's null, we'll throw a NullReferenceException if (!typeof(IRegisteredObject).IsAssignableFrom(type)) { throw new ArgumentException(String.Concat("Type '", type.Name, "' does not implement IRegisteredObject."), "type"); } // // ArgumentException is thrown for the physical path from the internal object created // in the new application domain. BareApplicationHost host = null; if (id_to_host.ContainsKey(appId)) { host = id_to_host [appId]; } IRegisteredObject ireg = null; if (host != null) { ireg = CheckIfExists(host, type, failIfExists); if (ireg != null) { return(ireg); } } try { if (host == null) { host = CreateHost(appId, virtualPath, physicalPath); } ireg = host.CreateInstance(type); } catch (Exception) { if (throwOnError) { throw; } } if (ireg != null && host.GetObject(type) == null) // If not registered from ctor... { host.RegisterObject(ireg, true); } return(ireg); }
IRegisteredObject CheckIfExists (BareApplicationHost host, Type type, bool failIfExists) { IRegisteredObject ireg = host.GetObject (type); if (ireg == null) return null; if (failIfExists) throw new InvalidOperationException (String.Concat ("Well known object of type '", type.Name, "' already exists in this domain.")); return ireg; }