diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2012-12-31 23:33:48 -0800 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2012-12-31 23:33:48 -0800 |
commit | a72f4df236e67f9c965863b6c43954b085cf8f6b (patch) | |
tree | 934464a1875a720a46d236fab598e41f481e7d66 /src/DotNetOpenAuth.Core/Configuration | |
parent | 124fa3c08787ccc43e8f5fac204e7448a6c1bbad (diff) | |
download | DotNetOpenAuth-a72f4df236e67f9c965863b6c43954b085cf8f6b.zip DotNetOpenAuth-a72f4df236e67f9c965863b6c43954b085cf8f6b.tar.gz DotNetOpenAuth-a72f4df236e67f9c965863b6c43954b085cf8f6b.tar.bz2 |
Fixes default ctor argument of identifier discovery services.
Diffstat (limited to 'src/DotNetOpenAuth.Core/Configuration')
-rw-r--r-- | src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs | 4 | ||||
-rw-r--r-- | src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs | 25 |
2 files changed, 20 insertions, 9 deletions
diff --git a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs index 08bd2a1..0eab939 100644 --- a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs +++ b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationCollection.cs @@ -42,10 +42,10 @@ namespace DotNetOpenAuth.Configuration { /// </summary> /// <param name="allowInternals">if set to <c>true</c> then internal types may be instantiated.</param> /// <returns>A sequence of instances generated from types in this collection. May be empty, but never null.</returns> - internal IEnumerable<T> CreateInstances(bool allowInternals) { + internal IEnumerable<T> CreateInstances(bool allowInternals, IHostFactories hostFactories) { return from element in this.Cast<TypeConfigurationElement<T>>() where !element.IsEmpty - select element.CreateInstance(default(T), allowInternals); + select element.CreateInstance(default(T), allowInternals, hostFactories); } /// <summary> diff --git a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs index d554832..8b3efe0 100644 --- a/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs +++ b/src/DotNetOpenAuth.Core/Configuration/TypeConfigurationElement.cs @@ -76,8 +76,8 @@ namespace DotNetOpenAuth.Configuration { /// </summary> /// <param name="defaultValue">The value to return if no type is given in the .config file.</param> /// <returns>The newly instantiated type.</returns> - public T CreateInstance(T defaultValue) { - return this.CreateInstance(defaultValue, false); + public T CreateInstance(T defaultValue, IHostFactories hostFactories) { + return this.CreateInstance(defaultValue, false, hostFactories); } /// <summary> @@ -85,9 +85,13 @@ namespace DotNetOpenAuth.Configuration { /// </summary> /// <param name="defaultValue">The value to return if no type is given in the .config file.</param> /// <param name="allowInternals">if set to <c>true</c> then internal types may be instantiated.</param> - /// <returns>The newly instantiated type.</returns> + /// <param name="hostFactories">The host factories.</param> + /// <returns> + /// The newly instantiated type. + /// </returns> [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "No apparent problem. False positive?")] - public T CreateInstance(T defaultValue, bool allowInternals) { + public T CreateInstance(T defaultValue, bool allowInternals, IHostFactories hostFactories) { + T instance; if (this.CustomType != null) { if (!allowInternals) { // Although .NET will usually prevent our instantiating non-public types, @@ -95,7 +99,7 @@ namespace DotNetOpenAuth.Configuration { // But we don't want the host site to be able to do this, so we check ourselves. ErrorUtilities.VerifyArgument((this.CustomType.Attributes & TypeAttributes.Public) != 0, Strings.ConfigurationTypeMustBePublic, this.CustomType.FullName); } - return (T)Activator.CreateInstance(this.CustomType); + instance = (T)Activator.CreateInstance(this.CustomType); } else if (!string.IsNullOrEmpty(this.XamlSource)) { string source = this.XamlSource; if (source.StartsWith("~/", StringComparison.Ordinal)) { @@ -103,11 +107,18 @@ namespace DotNetOpenAuth.Configuration { source = HttpContext.Current.Server.MapPath(source); } using (Stream xamlFile = File.OpenRead(source)) { - return CreateInstanceFromXaml(xamlFile); + instance = CreateInstanceFromXaml(xamlFile); } } else { - return defaultValue; + instance = defaultValue; + } + + var requiresHostFactories = instance as IRequireHostFactories; + if (requiresHostFactories != null) { + requiresHostFactories.HostFactories = hostFactories; } + + return instance; } /// <summary> |