FromServicesAttribute FromServicesAttribute FromServicesAttribute Class

Definition

Specifies that an action parameter should be bound using the request services.

[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
type FromServicesAttribute = class
    inherit Attribute
    interface IBindingSourceMetadata
Public Class FromServicesAttribute
Inherits Attribute
Implements IBindingSourceMetadata
Inheritance
FromServicesAttributeFromServicesAttributeFromServicesAttribute
Attributes
Implements

Examples

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 request services.


 [HttpGet]
 public ProductModel GetProduct([FromServices] IProductModelRequestService productModelReqest)
 {
     return productModelReqest.Value;
 }
 

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 request services.


 [HttpGet]
 public ProductModel GetProduct([FromServices] IProductModelRequestService productModelRequest)
 {
     return productModelRequest.Value;
 }
 

Constructors

FromServicesAttribute() FromServicesAttribute() FromServicesAttribute()

Properties

BindingSource BindingSource BindingSource

Applies to