// 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.AspNet.Mvc.ModelBinding; 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 { /// public BindingSource BindingSource { get { return BindingSource.Services; } } } }