diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/DefaultOutputFormattersProvider.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/DefaultOutputFormattersProvider.cs
index 578f9de02b..a6b9ee64d4 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Formatters/DefaultOutputFormattersProvider.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/DefaultOutputFormattersProvider.cs
@@ -3,20 +3,15 @@
using System;
using System.Collections.Generic;
-using System.Linq;
-using Microsoft.AspNet.Mvc.ModelBinding;
+using Microsoft.AspNet.Mvc.OptionDescriptors;
using Microsoft.Framework.DependencyInjection;
using Microsoft.Framework.OptionsModel;
namespace Microsoft.AspNet.Mvc
{
///
- public class DefaultOutputFormattersProvider : IOutputFormattersProvider
+ public class DefaultOutputFormattersProvider : OptionDescriptorBasedProvider, IOutputFormattersProvider
{
- private readonly List _descriptors;
- private readonly ITypeActivator _typeActivator;
- private readonly IServiceProvider _serviceProvider;
-
///
/// Initializes a new instance of the DefaultOutputFormattersProvider class.
///
@@ -24,34 +19,19 @@ namespace Microsoft.AspNet.Mvc
/// An instance used to instantiate types.
/// A instance that retrieves services from the
/// service collection.
- public DefaultOutputFormattersProvider(IOptionsAccessor options,
+ public DefaultOutputFormattersProvider(IOptionsAccessor optionsAccessor,
ITypeActivator typeActivator,
IServiceProvider serviceProvider)
+ : base(optionsAccessor.Options.OutputFormatters, typeActivator, serviceProvider)
{
- _descriptors = options.Options.OutputFormatters;
- _typeActivator = typeActivator;
- _serviceProvider = serviceProvider;
}
-
+
///
public IReadOnlyList OutputFormatters
{
get
{
- var outputFormatters = new List();
- foreach (var descriptor in _descriptors)
- {
- var formatter = descriptor.OutputFormatter;
- if (formatter == null)
- {
- formatter = (IOutputFormatter)_typeActivator.CreateInstance(_serviceProvider,
- descriptor.OutputFormatterType);
- }
-
- outputFormatters.Add(formatter);
- }
-
- return outputFormatters;
+ return Options;
}
}
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptor.cs b/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptor.cs
index fff1e4bb4d..b5c11cd27d 100644
--- a/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptor.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptor.cs
@@ -6,14 +6,14 @@ using System;
namespace Microsoft.AspNet.Mvc.OptionDescriptors
{
///
- /// Encapsulates information that describes an .
+ /// Encapsulates information that describes an .
///
- public class OutputFormatterDescriptor : OptionDescriptor
+ public class OutputFormatterDescriptor : OptionDescriptor
{
///
/// Creates a new instance of .
///
- /// A A .
///
- /// An instance of
+ /// An instance of
/// that the descriptor represents.
- public OutputFormatterDescriptor([NotNull] OutputFormatter outputFormatter)
+ public OutputFormatterDescriptor([NotNull] IOutputFormatter outputFormatter)
: base(outputFormatter)
{
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptorExtensions.cs b/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptorExtensions.cs
index 1edb0d2b8a..786ea292c5 100644
--- a/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptorExtensions.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/OptionDescriptors/OutputFormatterDescriptorExtensions.cs
@@ -53,7 +53,7 @@ namespace Microsoft.AspNet.Mvc
/// An instance.
/// OutputFormatterDescriptor representing the added instance.
public static OutputFormatterDescriptor Add([NotNull] this IList descriptors,
- [NotNull] IOutputFormatter outputFormatter)
+ [NotNull] IOutputFormatter outputFormatter)
{
var descriptor = new OutputFormatterDescriptor(outputFormatter);
descriptors.Add(descriptor);
@@ -68,7 +68,7 @@ namespace Microsoft.AspNet.Mvc
/// OutputFormatterDescriptor representing the added instance.
public static OutputFormatterDescriptor Insert([NotNull] this IList descriptors,
int index,
- [NotNull] IOutputFormatter outputFormatter)
+ [NotNull] IOutputFormatter outputFormatter)
{
if (index < 0 || index > descriptors.Count)
{
diff --git a/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs b/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs
index e20173e1d3..f6acaed810 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/Properties/Resources.Designer.cs
@@ -1066,6 +1066,23 @@ namespace Microsoft.AspNet.Mvc.Core
return string.Format(CultureInfo.CurrentCulture, GetString("OutputFormatterNoEncoding"), p0);
}
+ ///
+ /// No supported media type registered for output formatter '{0}'. There must be at least one supported media type registered in order for the output formatter to write content.
+ ///
+ internal static string OutputFormatterNoMediaType
+ {
+ get { return GetString("OutputFormatterNoMediaType"); }
+ }
+
+ ///
+ /// No supported media type registered for output formatter '{0}'. There must be at least one supported media type registered in order for the output formatter to write content.
+ ///
+ internal static string FormatOutputFormatterNoMediaType(object p0)
+ {
+ return string.Format(CultureInfo.CurrentCulture, GetString("OutputFormatterNoMediaType"), p0);
+ }
+
+ ///
/// The following errors occurred with attribute routing information:{0}{0}{1}
///
internal static string AttributeRoute_AggregateErrorMessage
diff --git a/src/Microsoft.AspNet.Mvc.Core/Resources.resx b/src/Microsoft.AspNet.Mvc.Core/Resources.resx
index 0bc71cefec..0746343d75 100644
--- a/src/Microsoft.AspNet.Mvc.Core/Resources.resx
+++ b/src/Microsoft.AspNet.Mvc.Core/Resources.resx
@@ -322,8 +322,7 @@
The following errors occurred with attribute routing information:{0}{0}{1}
{0} is the newline. {1} is the formatted list of errors using AttributeRoute_IndividualErrorMessage
-
-
+
The attribute route '{0}' cannot contain a parameter named '{{{1}}}'. Use '[{1}]' in the route template to insert the value '{2}'.
diff --git a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs
index 113a5f0933..a248694dd0 100644
--- a/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs
+++ b/src/Microsoft.AspNet.Mvc/MvcOptionsSetup.cs
@@ -33,7 +33,7 @@ namespace Microsoft.AspNet.Mvc
options.ModelBinders.Add(new ComplexModelDtoModelBinder());
// Set up default output formatters.
- options.OutputFormatters.Add(new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true));
+ options.OutputFormatters.Add(new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false));
// Set up ValueProviders
options.ValueProviderFactories.Add(new RouteValueValueProviderFactory());
diff --git a/src/Microsoft.AspNet.Mvc/MvcServices.cs b/src/Microsoft.AspNet.Mvc/MvcServices.cs
index fed6fc241b..5e684c7547 100644
--- a/src/Microsoft.AspNet.Mvc/MvcServices.cs
+++ b/src/Microsoft.AspNet.Mvc/MvcServices.cs
@@ -66,9 +66,11 @@ namespace Microsoft.AspNet.Mvc
yield return describe.Transient();
yield return describe.Transient();
+ yield return describe.Transient();
+ yield return describe.Scoped();
+ yield return describe.Transient();
+ yield return describe.Scoped();
yield return describe.Transient();
- yield return describe.Transient();
- yield return describe.Transient();
yield return describe.Transient, DefaultFilterProvider>();
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectContentResultTests.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectContentResultTests.cs
index 15f57578c5..f5f8087611 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectContentResultTests.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ActionResults/ObjectContentResultTests.cs
@@ -79,7 +79,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
new CannotWriteFormatter(),
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
};
// Act
@@ -145,7 +145,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
new CannotWriteFormatter(),
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
};
// Act
await result.ExecuteResultAsync(actionContext);
@@ -177,7 +177,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
mockFormatter.Object,
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
new CannotWriteFormatter()
};
// Act
@@ -207,7 +207,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
new CannotWriteFormatter(),
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
};
// Act
@@ -238,7 +238,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
new CannotWriteFormatter(),
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
};
// Act
await result.ExecuteResultAsync(actionContext);
@@ -269,7 +269,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
result.Formatters = new List
{
new CannotWriteFormatter(),
- new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true),
+ new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false),
};
// Act
await result.ExecuteResultAsync(actionContext);
@@ -360,7 +360,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
Object = nonStringValue,
DeclaredType = nonStringValue.GetType()
};
- var formatter = new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), true);
+ var formatter = new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), false);
formatter.WriteResponseContentHeaders(formatterContext);
await formatter.WriteAsync(formatterContext);
@@ -471,7 +471,7 @@ namespace Microsoft.AspNet.Mvc.Core.Test.ActionResults
get
{
return new List()
- { new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), indent: true) };
+ { new JsonOutputFormatter(JsonOutputFormatter.CreateDefaultSettings(), indent: false) };
}
}
}
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorExtensionTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorExtensionTest.cs
index 18d7442130..0f95d1a384 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorExtensionTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/OptionDescriptors/OutputFormatterDescriptorExtensionTest.cs
@@ -4,6 +4,7 @@
#if NET45
using System;
using System.Collections.Generic;
+using Microsoft.AspNet.Mvc.OptionDescriptors;
using Moq;
using Xunit;
@@ -63,10 +64,10 @@ namespace Microsoft.AspNet.Mvc.Core.Test
// Assert
Assert.Equal(4, collection.Count);
- Assert.Equal(formatter1, collection[0].OutputFormatter);
- Assert.Equal(formatter2, collection[1].OutputFormatter);
- Assert.Equal(type2, collection[2].OutputFormatterType);
- Assert.Equal(type1, collection[3].OutputFormatterType);
+ Assert.Equal(formatter1, collection[0].Instance);
+ Assert.Equal(formatter2, collection[1].Instance);
+ Assert.Equal(type2, collection[2].OptionType);
+ Assert.Equal(type1, collection[3].OptionType);
}
}
}