diff --git a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs index 9784d5d4c2..acca803108 100644 --- a/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs +++ b/src/Microsoft.AspNet.Mvc.ViewFeatures/Controller.cs @@ -14,6 +14,7 @@ using Microsoft.AspNet.Mvc.ModelBinding; using Microsoft.AspNet.Mvc.ModelBinding.Validation; using Microsoft.AspNet.Mvc.ViewFeatures; using Microsoft.AspNet.Routing; +using Microsoft.Framework.DependencyInjection; using Microsoft.Framework.Internal; using Microsoft.Net.Http.Headers; using Newtonsoft.Json; @@ -25,9 +26,13 @@ namespace Microsoft.AspNet.Mvc /// public abstract class Controller : IActionFilter, IAsyncActionFilter, IDisposable { + private ActionContext _actionContext; + private IModelMetadataProvider _metadataProvider; + private IObjectModelValidator _objectValidator; + private ITempDataDictionary _tempData; + private IUrlHelper _url; private DynamicViewData _viewBag; private ViewDataDictionary _viewData; - private ActionContext _actionContext; /// /// Gets the request-specific . @@ -131,17 +136,68 @@ namespace Microsoft.AspNet.Mvc /// /// Gets or sets the . /// - [FromServices] - public IModelMetadataProvider MetadataProvider { get; set; } + public IModelMetadataProvider MetadataProvider + { + get + { + if (_metadataProvider == null) + { + _metadataProvider = Resolver?.GetRequiredService(); + } + + return _metadataProvider; + } + + [param: NotNull] + set + { + _metadataProvider = value; + } + } /// /// Gets or sets the . /// - [FromServices] - public IUrlHelper Url { get; set; } + public IUrlHelper Url + { + get + { + if (_url == null) + { + _url = Resolver?.GetRequiredService(); + } - [FromServices] - public IObjectModelValidator ObjectValidator { get; set; } + return _url; + } + + [param: NotNull] + set + { + _url = value; + } + } + + /// + /// Gets or sets the . + /// + public IObjectModelValidator ObjectValidator + { + get + { + if (_objectValidator == null) + { + _objectValidator = Resolver?.GetRequiredService(); + } + + return _objectValidator; + } + + [param: NotNull] + set + { + _objectValidator = value; + } + } /// /// Gets or sets the for user associated with the executing action. @@ -192,8 +248,24 @@ namespace Microsoft.AspNet.Mvc /// /// Gets or sets used by . /// - [FromServices] - public ITempDataDictionary TempData { get; set; } + public ITempDataDictionary TempData + { + get + { + if (_tempData == null) + { + _tempData = Resolver?.GetRequiredService(); + } + + return _tempData; + } + + [param: NotNull] + set + { + _tempData = value; + } + } /// /// Gets the dynamic view bag.