Skip to content
This repository has been archived by the owner on Dec 14, 2018. It is now read-only.

Commit

Permalink
* Simplify MvcOptions
Browse files Browse the repository at this point in the history
* Remove facades for accessing Options<T> and pass options to the invoker

Fixes #2266
Fixes #2269
  • Loading branch information
pranavkm committed Apr 3, 2015
1 parent 6058ad0 commit 4613d37
Show file tree
Hide file tree
Showing 113 changed files with 929 additions and 3,985 deletions.
22 changes: 22 additions & 0 deletions ConsoleApplication1/ConsoleApplication1.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.22731.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApplication1", "ConsoleApplication1\ConsoleApplication1.csproj", "{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
6 changes: 6 additions & 0 deletions ConsoleApplication1/ConsoleApplication1/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
</configuration>
59 changes: 59 additions & 0 deletions ConsoleApplication1/ConsoleApplication1/ConsoleApplication1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{71395491-FCC5-40AC-8D45-1C3A0D97F1FF}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>ConsoleApplication1</RootNamespace>
<AssemblyName>ConsoleApplication1</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
27 changes: 27 additions & 0 deletions ConsoleApplication1/ConsoleApplication1/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{

var t = typeof(IList<string>);

if (t.IsGenericType)
{
var y = typeof(IList<>);
if (y.IsAssignableFrom(t.GetGenericTypeDefinition()))
{
Console.WriteLine("Hello");
}
}

}
}
}
36 changes: 36 additions & 0 deletions ConsoleApplication1/ConsoleApplication1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("ConsoleApplication1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApplication1")]
[assembly: AssemblyCopyright("Copyright © 2015")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("71395491-fcc5-40ac-8d45-1c3a0d97f1ff")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
10 changes: 6 additions & 4 deletions src/Microsoft.AspNet.Mvc.Core/ActionResults/ObjectResult.cs
Original file line number Diff line number Diff line change
Expand Up @@ -273,10 +273,12 @@ private IEnumerable<IOutputFormatter> GetDefaultFormatters(ActionContext context
IEnumerable<IOutputFormatter> formatters = null;
if (Formatters == null || Formatters.Count == 0)
{
formatters = context.HttpContext
.RequestServices
.GetRequiredService<IOutputFormattersProvider>()
.OutputFormatters;
formatters = context
.HttpContext
.RequestServices
.GetRequiredService<IOptions<MvcOptions>>()
.Options
.OutputFormatters;
}
else
{
Expand Down
16 changes: 8 additions & 8 deletions src/Microsoft.AspNet.Mvc.Core/ControllerActionInvoker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ public class ControllerActionInvoker : FilterActionInvoker
[NotNull] IReadOnlyList<IFilterProvider> filterProviders,
[NotNull] IControllerFactory controllerFactory,
[NotNull] ControllerActionDescriptor descriptor,
[NotNull] IInputFormattersProvider inputFormatterProvider,
[NotNull] IReadOnlyList<IInputFormatter> inputFormatters,
[NotNull] IControllerActionArgumentBinder controllerActionArgumentBinder,
[NotNull] IModelBinderProvider modelBinderProvider,
[NotNull] IModelValidatorProviderProvider modelValidatorProviderProvider,
[NotNull] IValueProviderFactoryProvider valueProviderFactoryProvider,
[NotNull] IReadOnlyList<IModelBinder> modelBinders,
[NotNull] IReadOnlyList<IModelValidatorProvider> modelValidatorProviders,
[NotNull] IReadOnlyList<IValueProviderFactory> valueProviderFactories,
[NotNull] IScopedInstance<ActionBindingContext> actionBindingContextAccessor,
[NotNull] ITempDataDictionary tempData)
: base(
actionContext,
filterProviders,
inputFormatterProvider,
modelBinderProvider,
modelValidatorProviderProvider,
valueProviderFactoryProvider,
inputFormatters,
modelBinders,
modelValidatorProviders,
valueProviderFactories,
actionBindingContextAccessor)
{
_descriptor = descriptor;
Expand Down
30 changes: 14 additions & 16 deletions src/Microsoft.AspNet.Mvc.Core/ControllerActionInvokerProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;

namespace Microsoft.AspNet.Mvc.Core
{
Expand All @@ -14,31 +15,28 @@ public class ControllerActionInvokerProvider : IActionInvokerProvider
private readonly IControllerActionArgumentBinder _argumentBinder;
private readonly IControllerFactory _controllerFactory;
private readonly IFilterProvider[] _filterProviders;
private readonly IInputFormattersProvider _inputFormattersProvider;
private readonly IModelBinderProvider _modelBinderProvider;
private readonly IModelValidatorProviderProvider _modelValidationProviderProvider;
private readonly IValueProviderFactoryProvider _valueProviderFactoryProvider;
private readonly IReadOnlyList<IInputFormatter> _inputFormatters;
private readonly IReadOnlyList<IModelBinder> _modelBinders;
private readonly IReadOnlyList<IModelValidatorProvider> _modelValidatorProviders;
private readonly IReadOnlyList<IValueProviderFactory> _valueProviderFactories;
private readonly IScopedInstance<ActionBindingContext> _actionBindingContextAccessor;
private readonly ITempDataDictionary _tempData;

public ControllerActionInvokerProvider(
IControllerFactory controllerFactory,
IInputFormattersProvider inputFormattersProvider,
IEnumerable<IFilterProvider> filterProviders,
IControllerActionArgumentBinder argumentBinder,
IModelBinderProvider modelBinderProvider,
IModelValidatorProviderProvider modelValidationProviderProvider,
IValueProviderFactoryProvider valueProviderFactoryProvider,
IOptions<MvcOptions> optionsAccessor,
IScopedInstance<ActionBindingContext> actionBindingContextAccessor,
ITempDataDictionary tempData)
{
_controllerFactory = controllerFactory;
_inputFormattersProvider = inputFormattersProvider;
_filterProviders = filterProviders.OrderBy(item => item.Order).ToArray();
_argumentBinder = argumentBinder;
_modelBinderProvider = modelBinderProvider;
_modelValidationProviderProvider = modelValidationProviderProvider;
_valueProviderFactoryProvider = valueProviderFactoryProvider;
_inputFormatters = optionsAccessor.Options.InputFormatters.ToArray();
_modelBinders = optionsAccessor.Options.ModelBinders.ToArray();
_modelValidatorProviders = optionsAccessor.Options.ModelValidatorProviders.ToArray();
_valueProviderFactories = optionsAccessor.Options.ValueProviderFactories.ToArray();
_actionBindingContextAccessor = actionBindingContextAccessor;
_tempData = tempData;
}
Expand All @@ -60,11 +58,11 @@ public void OnProvidersExecuting([NotNull] ActionInvokerProviderContext context)
_filterProviders,
_controllerFactory,
actionDescriptor,
_inputFormattersProvider,
_inputFormatters,
_argumentBinder,
_modelBinderProvider,
_modelValidationProviderProvider,
_valueProviderFactoryProvider,
_modelBinders,
_modelValidatorProviders,
_valueProviderFactories,
_actionBindingContextAccessor,
_tempData);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc.Core;
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Metadata;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
Expand Down Expand Up @@ -37,7 +35,7 @@ public class DefaultControllerActionArgumentBinder : IControllerActionArgumentBi

public async Task<IDictionary<string, object>> BindActionArgumentsAsync(
ActionContext actionContext,
ActionBindingContext actionBindingContext,
ActionBindingContext actionBindingContext,
object controller)
{
var actionDescriptor = actionContext.ActionDescriptor as ControllerActionDescriptor;
Expand Down Expand Up @@ -66,7 +64,7 @@ public class DefaultControllerActionArgumentBinder : IControllerActionArgumentBi
actionArguments,
actionDescriptor.Parameters);
return actionArguments;
}
}

private void ActivateProperties(object controller, Type containerType, Dictionary<string, object> properties)
{
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.AspNet.Routing;
using Microsoft.AspNet.Routing.Template;
using Microsoft.Framework.Internal;
using Microsoft.Framework.OptionsModel;
using Microsoft.Net.Http.Headers;

namespace Microsoft.AspNet.Mvc.Description
Expand All @@ -21,21 +22,23 @@ namespace Microsoft.AspNet.Mvc.Description
/// </summary>
public class DefaultApiDescriptionProvider : IApiDescriptionProvider
{
private readonly IOutputFormattersProvider _formattersProvider;
private readonly IList<IOutputFormatter> _outputFormatters;
private readonly IModelMetadataProvider _modelMetadataProvider;
private readonly IInlineConstraintResolver _constraintResolver;

/// <summary>
/// Creates a new instance of <see cref="DefaultApiDescriptionProvider"/>.
/// </summary>
/// <param name="formattersProvider">The <see cref="IOutputFormattersProvider"/>.</param>
/// <param name="optionsAccessor">The accessor for <see cref="MvcOptions"/>.</param>
/// <param name="constraintResolver">The <see cref="IInlineConstraintResolver"/> used for resolving inline
/// constraints.</param>
/// <param name="modelMetadataProvider">The <see cref="IModelMetadataProvider"/>.</param>
public DefaultApiDescriptionProvider(
IOutputFormattersProvider formattersProvider,
IOptions<MvcOptions> optionsAccessor,
IInlineConstraintResolver constraintResolver,
IModelMetadataProvider modelMetadataProvider)
{
_formattersProvider = formattersProvider;
_outputFormatters = optionsAccessor.Options.OutputFormatters;
_constraintResolver = constraintResolver;
_modelMetadataProvider = modelMetadataProvider;
}
Expand Down Expand Up @@ -316,10 +319,9 @@ private string GetRelativePath(RouteTemplate parsedTemplate)
contentTypes.Add(null);
}

var formatters = _formattersProvider.OutputFormatters;
foreach (var contentType in contentTypes)
{
foreach (var formatter in formatters)
foreach (var formatter in _outputFormatters)
{
var responseFormatMetadataProvider = formatter as IApiResponseFormatMetadataProvider;
if (responseFormatMetadataProvider != null)
Expand Down

0 comments on commit 4613d37

Please sign in to comment.