diff --git a/samples/MvcSample.Web/HomeController.cs b/samples/MvcSample.Web/HomeController.cs
index 916a81639c..6b801df75d 100644
--- a/samples/MvcSample.Web/HomeController.cs
+++ b/samples/MvcSample.Web/HomeController.cs
@@ -93,13 +93,12 @@ public ActionResult SaveUser(User user)
return View("MyView", user);
}
- [FromServices]
- public IHostingEnvironment HostingEnvironment { get; set; }
-
///
/// Action that shows multiple file upload.
///
- public async Task PostFile(IList files)
+ public async Task PostFile(
+ [FromServices] IHostingEnvironment hostingEnvironment,
+ IList files)
{
if (!ModelState.IsValid)
{
@@ -108,7 +107,7 @@ public async Task PostFile(IList files)
foreach (var f in files)
{
- await f.SaveAsAsync(Path.Combine(HostingEnvironment.WebRootPath, "test-file" + files.IndexOf(f)));
+ await f.SaveAsAsync(Path.Combine(hostingEnvironment.WebRootPath, "test-file" + files.IndexOf(f)));
}
return View();
}
diff --git a/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs
index bd51dfb6cc..ca07ad18dd 100644
--- a/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs
+++ b/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs
@@ -7,25 +7,9 @@
namespace Microsoft.AspNet.Mvc
{
///
- /// Specifies that a parameter or property should be bound using the request services.
+ /// Specifies that an action parameter should be bound using the request services.
///
///
- /// In this example, the LocationService property on the VehicleWithDealerViewModel class
- /// will be bound to the value resolved for the ILocationService service from the request services.
- ///
- ///
- /// public class VehicleWithDealerViewModel
- /// {
- /// [FromServices]
- /// public ILocationService LocationService { get; set; }
- ///
- /// public void Update()
- /// {
- /// LocationService.Update();
- /// }
- /// }
- ///
- ///
/// In this example an implementation of IProductModelRequestService is registered as a service.
/// Then in the GetProduct action, the parameter is bound to an instance of IProductModelRequestService
/// which is resolved from the the request services.
@@ -38,10 +22,10 @@ namespace Microsoft.AspNet.Mvc
/// }
///
///
- [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
+ [AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = true)]
public class FromServicesAttribute : Attribute, IBindingSourceMetadata
{
///
- public BindingSource BindingSource { get { return BindingSource.Services; } }
+ public BindingSource BindingSource => BindingSource.Services;
}
}
diff --git a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ApiController.cs b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ApiController.cs
index 61dca0573a..3c0bca9f3c 100644
--- a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ApiController.cs
+++ b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ApiController.cs
@@ -10,6 +10,7 @@
using Microsoft.AspNet.Mvc.ModelBinding;
using Microsoft.AspNet.Mvc.ModelBinding.Validation;
using Microsoft.AspNet.Mvc.WebApiCompatShim;
+using Microsoft.Extensions.DependencyInjection;
using Microsoft.Net.Http.Headers;
using Newtonsoft.Json;
@@ -22,6 +23,9 @@ namespace System.Web.Http
public abstract class ApiController : IDisposable
{
private HttpRequestMessage _request;
+ private IModelMetadataProvider _metadataProvider;
+ private IObjectModelValidator _objectValidator;
+ private IUrlHelper _urlHelper;
///
/// Gets the action context.
@@ -52,12 +56,42 @@ public HttpContext Context
/// Gets the .
///
/// The setter is intended for unit testing purposes only.
- [FromServices]
- public IModelMetadataProvider MetadataProvider { get; set; }
+ public IModelMetadataProvider MetadataProvider
+ {
+ get
+ {
+ if (_metadataProvider == null)
+ {
+ _metadataProvider = Context?.RequestServices?.GetRequiredService();
+ }
+ return _metadataProvider;
+ }
+ set
+ {
+ _metadataProvider = value;
+ }
+ }
+
+ ///
+ /// Gets or sets the .
+ ///
+ public IObjectModelValidator ObjectValidator
+ {
+ get
+ {
+ if (_objectValidator == null)
+ {
+ _objectValidator = Context?.RequestServices?.GetRequiredService();
+ }
- [FromServices]
- public IObjectModelValidator ObjectValidator { get; set; }
+ return _objectValidator;
+ }
+ set
+ {
+ _objectValidator = value;
+ }
+ }
///
/// Gets model state after the model binding process. This ModelState will be empty before model binding
@@ -96,8 +130,22 @@ public HttpRequestMessage Request
/// Gets a factory used to generate URLs to other APIs.
///
/// The setter is intended for unit testing purposes only.
- [FromServices]
- public IUrlHelper Url { get; set; }
+ public IUrlHelper Url
+ {
+ get
+ {
+ if (_urlHelper == null)
+ {
+ _urlHelper = Context?.RequestServices?.GetRequiredService();
+ }
+
+ return _urlHelper;
+ }
+ set
+ {
+ _urlHelper = value;
+ }
+ }
///
/// Gets or sets the current principal associated with this request.
diff --git a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs
index 8fc67160b2..1db2a31ef1 100644
--- a/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs
+++ b/test/Microsoft.AspNet.Mvc.Core.Test/ModelBinding/Metadata/ModelAttributesTest.cs
@@ -190,9 +190,6 @@ private class BaseModel
[Required]
public virtual int VirtualProperty { get; set; }
-
- [FromServices]
- public ICalculator Calculator { get; set; }
}
private class DerivedModel : BaseModel
diff --git a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs
index c52a10e8f2..068d6421db 100644
--- a/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs
+++ b/test/Microsoft.AspNet.Mvc.FunctionalTests/RequestServicesTest.cs
@@ -25,7 +25,6 @@ public RequestServicesTest(MvcTestFixture fixtur
[InlineData("http://localhost/Other/FromFilter")]
[InlineData("http://localhost/Other/FromView")]
[InlineData("http://localhost/Other/FromViewComponent")]
- [InlineData("http://localhost/Other/FromModelProperty")]
[InlineData("http://localhost/Other/FromActionArgument")]
public async Task RequestServices(string url)
{
@@ -40,6 +39,7 @@ public async Task RequestServices(string url)
var response = await Client.SendAsync(request);
// Assert
+ response.EnsureSuccessStatusCode();
var body = (await response.Content.ReadAsStringAsync()).Trim();
Assert.Equal(requestId, body);
}
diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs
index 58b0648a72..d2ecec2110 100644
--- a/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs
+++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/MutableObjectModelBinderIntegrationTest.cs
@@ -268,9 +268,6 @@ private class Order2
private class Person2
{
public string Name { get; set; }
-
- [FromServices]
- public IActionBindingContextAccessor BindingContext { get; set; }
}
[Fact]
@@ -301,7 +298,6 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind
var model = Assert.IsType(modelBindingResult.Model);
Assert.NotNull(model.Customer);
Assert.Equal("bill", model.Customer.Name);
- Assert.NotNull(model.Customer.BindingContext);
Assert.Equal(1, modelState.Count);
Assert.Equal(0, modelState.ErrorCount);
@@ -340,7 +336,6 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithServicesModelBind
var model = Assert.IsType(modelBindingResult.Model);
Assert.NotNull(model.Customer);
Assert.Equal("bill", model.Customer.Name);
- Assert.NotNull(model.Customer.BindingContext);
Assert.Equal(1, modelState.Count);
Assert.Equal(0, modelState.ErrorCount);
@@ -1489,9 +1484,6 @@ private class Person9
{
[FromBody]
public Address1 Address { get; set; }
-
- [FromServices]
- public IActionBindingContextAccessor BindingContext { get; set; }
}
// If a nested POCO object has all properties bound from a greedy source, then it should be populated
@@ -1524,7 +1516,6 @@ public async Task MutableObjectModelBinder_BindsNestedPOCO_WithAllGreedyBoundPro
var model = Assert.IsType(modelBindingResult.Model);
Assert.NotNull(model.Customer);
- Assert.NotNull(model.Customer.BindingContext);
Assert.NotNull(model.Customer.Address);
Assert.Equal(AddressStreetContent, model.Customer.Address.Street);
diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs
index 3e8ea213fc..220f3c70b3 100644
--- a/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs
+++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/ServicesModelBinderIntegrationTest.cs
@@ -13,90 +13,6 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
{
public class ServicesModelBinderIntegrationTest
{
- private class Person
- {
- public Address Address { get; set; }
- }
-
- private class Address
- {
- // Using a service type already in defaults.
- [FromServices]
- public JsonOutputFormatter OutputFormatter { get; set; }
- }
-
- [Fact]
- public async Task BindPropertyFromService_WithData_WithPrefix_GetsBound()
- {
- // Arrange
- var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
- var parameter = new ParameterDescriptor()
- {
- Name = "Parameter1",
- BindingInfo = new BindingInfo()
- {
- BinderModelName = "CustomParameter",
- },
-
- ParameterType = typeof(Person)
- };
-
- var operationContext = ModelBindingTestHelper.GetOperationBindingContext();
- var modelState = new ModelStateDictionary();
-
- // Act
- var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
-
- // Assert
-
- // ModelBindingResult
- Assert.True(modelBindingResult.IsModelSet);
-
- // Model
- var boundPerson = Assert.IsType(modelBindingResult.Model);
- Assert.NotNull(boundPerson);
- Assert.NotNull(boundPerson.Address.OutputFormatter);
-
- // ModelState
- Assert.True(modelState.IsValid);
- Assert.Empty(modelState.Keys);
- }
-
- [Fact]
- public async Task BindPropertyFromService_WithData_WithEmptyPrefix_GetsBound()
- {
- // Arrange
- var argumentBinder = ModelBindingTestHelper.GetArgumentBinder();
- var parameter = new ParameterDescriptor()
- {
- Name = "Parameter1",
- BindingInfo = new BindingInfo(),
- ParameterType = typeof(Person)
- };
-
- var operationContext = ModelBindingTestHelper.GetOperationBindingContext();
- var modelState = new ModelStateDictionary();
-
- // Act
- var modelBindingResult = await argumentBinder.BindModelAsync(parameter, modelState, operationContext);
-
- // Assert
-
- // ModelBindingResult
- Assert.True(modelBindingResult.IsModelSet);
-
- // Model
- var boundPerson = Assert.IsType(modelBindingResult.Model);
- Assert.NotNull(boundPerson);
- Assert.NotNull(boundPerson.Address.OutputFormatter);
-
- // ModelState
- Assert.True(modelState.IsValid);
-
- // For non user bound models there should be no entry in model state.
- Assert.Empty(modelState);
- }
-
[Fact]
public async Task BindParameterFromService_WithData_GetsBound()
{
diff --git a/test/WebSites/ActionResultsWebSite/Controllers/ActionResultsVerificationController.cs b/test/WebSites/ActionResultsWebSite/Controllers/ActionResultsVerificationController.cs
index 0fde891c37..d55cc44802 100644
--- a/test/WebSites/ActionResultsWebSite/Controllers/ActionResultsVerificationController.cs
+++ b/test/WebSites/ActionResultsWebSite/Controllers/ActionResultsVerificationController.cs
@@ -10,9 +10,12 @@ namespace ActionResultsWebSite
{
public class ActionResultsVerificationController : Controller
{
+ public ActionResultsVerificationController(GuidLookupService guidLookupService)
+ {
+ GuidLookupService = guidLookupService;
+ }
- [FromServices]
- public GuidLookupService Service { get; set; }
+ public GuidLookupService GuidLookupService { get; }
public IActionResult Index([FromBody]DummyClass test)
{
@@ -107,7 +110,7 @@ public IActionResult GetNotFoundObjectResultWithDisposableObject(string guid)
public bool GetDisposeCalled(string guid)
{
bool value;
- if (Service.IsDisposed.TryGetValue(guid, out value))
+ if (GuidLookupService.IsDisposed.TryGetValue(guid, out value))
{
return value;
}
@@ -131,7 +134,7 @@ private DummyClass CreateDummy()
private DisposableType CreateDisposableType(string guid)
{
- return new DisposableType(Service, guid);
+ return new DisposableType(GuidLookupService, guid);
}
private class DisposableType : IDisposable
diff --git a/test/WebSites/ActivatorWebSite/Controllers/PlainController.cs b/test/WebSites/ActivatorWebSite/Controllers/PlainController.cs
index 2cdbf4ce80..8dfe1a41ea 100644
--- a/test/WebSites/ActivatorWebSite/Controllers/PlainController.cs
+++ b/test/WebSites/ActivatorWebSite/Controllers/PlainController.cs
@@ -8,9 +8,6 @@ namespace ActivatorWebSite
{
public class PlainController
{
- [FromServices]
- public MyService Service { get; set; }
-
[ActionContext]
public ActionContext ActionContext { get; set; }
@@ -18,12 +15,12 @@ public class PlainController
public HttpResponse Response => ActionContext.HttpContext.Response;
- public IActionResult Index()
+ public IActionResult Index([FromServices] MyService service)
{
Response.Headers["X-Fake-Header"] = "Fake-Value";
var value = Request.Query["foo"];
- return new ContentResult { Content = Service.Random + "|" + value };
+ return new ContentResult { Content = service.Random + "|" + value };
}
}
}
\ No newline at end of file
diff --git a/test/WebSites/ApiExplorerWebSite/Models/OrderDTO.cs b/test/WebSites/ApiExplorerWebSite/Models/OrderDTO.cs
index 402477eddb..e677324039 100644
--- a/test/WebSites/ApiExplorerWebSite/Models/OrderDTO.cs
+++ b/test/WebSites/ApiExplorerWebSite/Models/OrderDTO.cs
@@ -7,9 +7,6 @@ namespace ApiExplorerWebSite
{
public class OrderDTO
{
- [FromServices]
- public IOrderRepository Repository { get; set; }
-
public string CustomerId { get; set; }
[FromHeader(Name = "Referrer")]
diff --git a/test/WebSites/HtmlGenerationWebSite/Controllers/Catalog_CacheTagHelperController.cs b/test/WebSites/HtmlGenerationWebSite/Controllers/Catalog_CacheTagHelperController.cs
index 9153730355..cabce61c4d 100644
--- a/test/WebSites/HtmlGenerationWebSite/Controllers/Catalog_CacheTagHelperController.cs
+++ b/test/WebSites/HtmlGenerationWebSite/Controllers/Catalog_CacheTagHelperController.cs
@@ -8,9 +8,6 @@ namespace HtmlGenerationWebSite.Controllers
{
public class Catalog_CacheTagHelperController : Controller
{
- [FromServices]
- public ProductsService ProductsService { get; set; }
-
[HttpGet("/catalog")]
public IActionResult Splash(int categoryId, int correlationId, [FromHeader] string locale)
{
@@ -75,9 +72,9 @@ public IActionResult ListCategories(string category, int correlationId)
}
[HttpPost("/categories/update-products")]
- public void UpdateCategories()
+ public void UpdateCategories([FromServices] ProductsService productsService)
{
- ProductsService.UpdateProducts();
+ productsService.UpdateProducts();
}
[HttpGet("/catalog/GetDealPercentage/{dealPercentage}")]
diff --git a/test/WebSites/ModelBindingWebSite/CaculatorContext.cs b/test/WebSites/ModelBindingWebSite/CaculatorContext.cs
index a8d0a8c192..4dbff4854c 100644
--- a/test/WebSites/ModelBindingWebSite/CaculatorContext.cs
+++ b/test/WebSites/ModelBindingWebSite/CaculatorContext.cs
@@ -7,9 +7,6 @@ namespace ModelBindingWebSite
{
public class CalculatorContext
{
- [FromServices]
- public ICalculator Calculator { get; set; }
-
public int Left { get; set; }
public int Right { get; set; }
diff --git a/test/WebSites/ModelBindingWebSite/Controllers/FromServices_CalculatorController.cs b/test/WebSites/ModelBindingWebSite/Controllers/FromServices_CalculatorController.cs
index 37fb9e7b26..9290ff1073 100644
--- a/test/WebSites/ModelBindingWebSite/Controllers/FromServices_CalculatorController.cs
+++ b/test/WebSites/ModelBindingWebSite/Controllers/FromServices_CalculatorController.cs
@@ -7,9 +7,9 @@ namespace ModelBindingWebSite.Controllers
{
public class FromServices_CalculatorController : Controller
{
- public int Calculate(CalculatorContext context)
+ public int Calculate(CalculatorContext context, [FromServices] ICalculator calculator)
{
- return context.Calculator.Operation(context.Operator, context.Left, context.Right);
+ return calculator.Operation(context.Operator, context.Left, context.Right);
}
public int Add(int left, int right, [FromServices] ICalculator calculator)
@@ -17,9 +17,9 @@ public int Add(int left, int right, [FromServices] ICalculator calculator)
return calculator.Operation('+', left, right);
}
- public int CalculateWithPrecision(DefaultCalculatorContext context)
+ public int CalculateWithPrecision(DefaultCalculatorContext context, [FromServices] ICalculator calculator)
{
- return context.Calculator.Operation(context.Operator, context.Left, context.Right);
+ return calculator.Operation(context.Operator, context.Left, context.Right);
}
}
}
\ No newline at end of file
diff --git a/test/WebSites/ModelBindingWebSite/Controllers/RoundtripController.cs b/test/WebSites/ModelBindingWebSite/Controllers/RoundtripController.cs
index 18263e2dad..38f0b9781f 100644
--- a/test/WebSites/ModelBindingWebSite/Controllers/RoundtripController.cs
+++ b/test/WebSites/ModelBindingWebSite/Controllers/RoundtripController.cs
@@ -18,7 +18,11 @@ public class RoundtripController : Controller
private IHtmlHelper _personHelper;
private bool _activated;
- [FromServices]
+ public RoundtripController(IHtmlHelper personHelper)
+ {
+ _personHelper = personHelper;
+ }
+
public IHtmlHelper PersonHelper
{
get
@@ -35,15 +39,11 @@ public IHtmlHelper PersonHelper
TextWriter.Null,
new HtmlHelperOptions());
- ((ICanHasViewContext)PersonHelper).Contextualize(context);
+ ((ICanHasViewContext)_personHelper).Contextualize(context);
}
return _personHelper;
}
- set
- {
- _personHelper = value;
- }
}
public string GetPerson()
diff --git a/test/WebSites/ModelBindingWebSite/Controllers/ValidationController.cs b/test/WebSites/ModelBindingWebSite/Controllers/ValidationController.cs
index 13dcea73ca..54e207233a 100644
--- a/test/WebSites/ModelBindingWebSite/Controllers/ValidationController.cs
+++ b/test/WebSites/ModelBindingWebSite/Controllers/ValidationController.cs
@@ -8,9 +8,6 @@ namespace ModelBindingWebSite.Controllers
[Route("Validation/[Action]")]
public class ValidationController : Controller
{
- [FromServices]
- public ITestService ControllerService { get; set; }
-
public object AvoidRecursive(SelfishPerson selfishPerson)
{
return ModelState.IsValid;
diff --git a/test/WebSites/ModelBindingWebSite/Controllers/VehicleController.cs b/test/WebSites/ModelBindingWebSite/Controllers/VehicleController.cs
index bbcb8df649..471877cfb2 100644
--- a/test/WebSites/ModelBindingWebSite/Controllers/VehicleController.cs
+++ b/test/WebSites/ModelBindingWebSite/Controllers/VehicleController.cs
@@ -59,7 +59,6 @@ public IActionResult UpdateDealerVehicle(VehicleWithDealerViewModel model)
return PartialView("UpdateVehicle", model);
}
- model.Update();
return PartialView("UpdateSuccessful", model);
}
diff --git a/test/WebSites/ModelBindingWebSite/Services/ILocationService.cs b/test/WebSites/ModelBindingWebSite/Services/ILocationService.cs
deleted file mode 100644
index 805c51379b..0000000000
--- a/test/WebSites/ModelBindingWebSite/Services/ILocationService.cs
+++ /dev/null
@@ -1,14 +0,0 @@
-// 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 ModelBindingWebSite.ViewModels;
-
-namespace ModelBindingWebSite.Services
-{
- public interface ILocationService
- {
- bool IsValidMakeForRegion(string make, string region);
-
- bool Update(VehicleWithDealerViewModel model);
- }
-}
\ No newline at end of file
diff --git a/test/WebSites/ModelBindingWebSite/Services/LocationService.cs b/test/WebSites/ModelBindingWebSite/Services/LocationService.cs
deleted file mode 100644
index d834e54918..0000000000
--- a/test/WebSites/ModelBindingWebSite/Services/LocationService.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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 ModelBindingWebSite.ViewModels;
-
-namespace ModelBindingWebSite.Services
-{
- public class LocationService : ILocationService
- {
- public bool Update(VehicleWithDealerViewModel viewModel)
- {
- return true;
- }
-
- public bool IsValidMakeForRegion(string make, string region)
- {
- switch (make)
- {
- case "Acme":
- return region == "NW" || "region" == "South Central";
- case "FastCars":
- return region != "Central";
- }
-
- return true;
- }
- }
-}
\ No newline at end of file
diff --git a/test/WebSites/ModelBindingWebSite/Startup.cs b/test/WebSites/ModelBindingWebSite/Startup.cs
index ec8a925850..920fe42870 100644
--- a/test/WebSites/ModelBindingWebSite/Startup.cs
+++ b/test/WebSites/ModelBindingWebSite/Startup.cs
@@ -2,7 +2,6 @@
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.AspNet.Builder;
-using Microsoft.AspNet.Mvc;
using Microsoft.Extensions.DependencyInjection;
using ModelBindingWebSite.Models;
using ModelBindingWebSite.Services;
@@ -32,7 +31,6 @@ public void ConfigureServices(IServiceCollection services)
services.AddSingleton();
services.AddTransient();
- services.AddTransient();
}
public void Configure(IApplicationBuilder app)
diff --git a/test/WebSites/ModelBindingWebSite/ViewModels/VehicleViewModel.cs b/test/WebSites/ModelBindingWebSite/ViewModels/VehicleViewModel.cs
index bf6ee2db8b..02e6f072db 100644
--- a/test/WebSites/ModelBindingWebSite/ViewModels/VehicleViewModel.cs
+++ b/test/WebSites/ModelBindingWebSite/ViewModels/VehicleViewModel.cs
@@ -38,8 +38,9 @@ public IEnumerable Validate(ValidationContext validationContex
{
if (InspectedDates.Any(d => d.Year > Year))
{
- yield return new ValidationResult("Inspection date cannot be later than year of manufacture.",
- new[] { nameof(InspectedDates) });
+ yield return new ValidationResult(
+ "Inspection date cannot be later than year of manufacture.",
+ new[] { nameof(InspectedDates) });
}
}
diff --git a/test/WebSites/ModelBindingWebSite/ViewModels/VehicleWithDealerViewModel.cs b/test/WebSites/ModelBindingWebSite/ViewModels/VehicleWithDealerViewModel.cs
index fa9cf89f34..7ae0c9b8be 100644
--- a/test/WebSites/ModelBindingWebSite/ViewModels/VehicleWithDealerViewModel.cs
+++ b/test/WebSites/ModelBindingWebSite/ViewModels/VehicleWithDealerViewModel.cs
@@ -4,7 +4,6 @@
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNet.Mvc;
-using ModelBindingWebSite.Services;
namespace ModelBindingWebSite.ViewModels
{
@@ -17,23 +16,28 @@ public class VehicleWithDealerViewModel : IValidatableObject
[FromBody]
public VehicleViewModel Vehicle { get; set; }
- [FromServices]
- public ILocationService LocationService { get; set; }
-
[FromHeader(Name = "X-TrackingId")]
public string TrackingId { get; set; } = "default-tracking-id";
public IEnumerable Validate(ValidationContext validationContext)
{
- if (!LocationService.IsValidMakeForRegion(Vehicle.Make, Dealer.Location))
+ if (!IsValidMakeForRegion(Vehicle.Make, Dealer.Location))
{
yield return new ValidationResult("Make is invalid for region.");
}
}
- public void Update()
+ public bool IsValidMakeForRegion(string make, string region)
{
- LocationService.Update(this);
+ switch (make)
+ {
+ case "Acme":
+ return region == "NW" || "region" == "South Central";
+ case "FastCars":
+ return region != "Central";
+ }
+
+ return true;
}
}
}
\ No newline at end of file
diff --git a/test/WebSites/RequestServicesWebSite/Controllers/OtherController.cs b/test/WebSites/RequestServicesWebSite/Controllers/OtherController.cs
index a856daa508..e04a45bb89 100644
--- a/test/WebSites/RequestServicesWebSite/Controllers/OtherController.cs
+++ b/test/WebSites/RequestServicesWebSite/Controllers/OtherController.cs
@@ -40,12 +40,6 @@ public IActionResult FromViewComponent()
return View("ViewComponent");
}
- [HttpGet]
- public string FromModelProperty(RequestModel requestContext)
- {
- return requestContext.RequestIdService.RequestId;
- }
-
[HttpGet]
public string FromActionArgument([FromServices] RequestIdService requestIdService)
{
diff --git a/test/WebSites/RequestServicesWebSite/Controllers/RequestScopedServiceController.cs b/test/WebSites/RequestServicesWebSite/Controllers/RequestScopedServiceController.cs
index 5e9db05f15..f79b55eb09 100644
--- a/test/WebSites/RequestServicesWebSite/Controllers/RequestScopedServiceController.cs
+++ b/test/WebSites/RequestServicesWebSite/Controllers/RequestScopedServiceController.cs
@@ -8,13 +8,10 @@ namespace RequestServicesWebSite
[Route("RequestScoped/[action]")]
public class RequestScopedServiceController
{
- [FromServices]
- public RequestIdService RequestIdService { get; set; }
-
[HttpGet]
- public string FromController()
+ public string FromController([FromServices] RequestIdService requestIdService)
{
- return RequestIdService.RequestId;
+ return requestIdService.RequestId;
}
}
}
\ No newline at end of file
diff --git a/test/WebSites/RequestServicesWebSite/Models/RequestModel.cs b/test/WebSites/RequestServicesWebSite/Models/RequestModel.cs
deleted file mode 100644
index 151efedc79..0000000000
--- a/test/WebSites/RequestServicesWebSite/Models/RequestModel.cs
+++ /dev/null
@@ -1,13 +0,0 @@
-// 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 Microsoft.AspNet.Mvc;
-
-namespace RequestServicesWebSite
-{
- public class RequestModel
- {
- [FromServices]
- public RequestIdService RequestIdService { get; set; }
- }
-}
\ No newline at end of file
diff --git a/test/WebSites/WebApiCompatShimWebSite/Controllers/BasicApiController.cs b/test/WebSites/WebApiCompatShimWebSite/Controllers/BasicApiController.cs
index 8efa312509..73945b2c44 100644
--- a/test/WebSites/WebApiCompatShimWebSite/Controllers/BasicApiController.cs
+++ b/test/WebSites/WebApiCompatShimWebSite/Controllers/BasicApiController.cs
@@ -15,9 +15,6 @@ namespace WebApiCompatShimWebSite
{
public class BasicApiController : ApiController
{
- [FromServices]
- public IOptions OptionsAccessor { get; set; }
-
// Verifies property activation
[HttpGet]
public async Task WriteToHttpContext()
@@ -43,9 +40,9 @@ public async Task GenerateUrl()
// Verifies the default options configure formatters correctly.
[HttpGet]
- public string[] GetFormatters()
+ public string[] GetFormatters([FromServices] IOptions optionsAccessor)
{
- return OptionsAccessor.Value.Formatters.Select(f => f.GetType().FullName).ToArray();
+ return optionsAccessor.Value.Formatters.Select(f => f.GetType().FullName).ToArray();
}
[HttpGet]