From 87c15bb6dc8fbb7672a6a5533a78de86cc23186f Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Thu, 10 Sep 2015 07:54:22 -0700 Subject: [PATCH] Adds/updates some docs for the FromServicesAttribute with examples --- .../FromServicesAttribute.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs b/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs index 8488bd7cf0..bd51dfb6cc 100644 --- a/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs +++ b/src/Microsoft.AspNet.Mvc.Core/FromServicesAttribute.cs @@ -9,6 +9,35 @@ namespace Microsoft.AspNet.Mvc /// /// Specifies that a parameter or property 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. + /// + /// + /// [HttpGet] + /// public ProductModel GetProduct([FromServices] IProductModelRequestService productModelReqest) + /// { + /// return productModelReqest.Value; + /// } + /// + /// [AttributeUsage(AttributeTargets.Parameter | AttributeTargets.Property, AllowMultiple = false, Inherited = true)] public class FromServicesAttribute : Attribute, IBindingSourceMetadata {