// Copyright (c) .NET Foundation. All rights reserved. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; using Microsoft.AspNetCore.Mvc.ApplicationModels; using Microsoft.AspNetCore.Mvc.Internal; using Microsoft.AspNetCore.Mvc.ViewFeatures.Internal; using Microsoft.Extensions.Options; namespace Microsoft.AspNetCore.Mvc.ViewFeatures { internal class TempDataApplicationModelProvider : IApplicationModelProvider { private readonly MvcViewOptions _options; public TempDataApplicationModelProvider(IOptions options) { _options = options.Value; } /// /// This order ensures that runs after the . public int Order => -1000 + 10; /// public void OnProvidersExecuted(ApplicationModelProviderContext context) { } /// public void OnProvidersExecuting(ApplicationModelProviderContext context) { if (context == null) { throw new ArgumentNullException(nameof(context)); } foreach (var controllerModel in context.Result.Controllers) { var modelType = controllerModel.ControllerType.AsType(); var tempDataProperties = SaveTempDataPropertyFilterBase.GetTempDataProperties(modelType, _options); if (tempDataProperties == null) { continue; } var filter = new ControllerSaveTempDataPropertyFilterFactory(tempDataProperties); controllerModel.Filters.Add(filter); } } } }