FromServicesAttribute Class

Definition

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

public ref class FromServicesAttribute : Attribute, Microsoft::AspNetCore::Mvc::ModelBinding::IBindingSourceMetadata
[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
[<System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)>]
type FromServicesAttribute = class
    inherit Attribute
    interface IBindingSourceMetadata
Public Class FromServicesAttribute
Inherits Attribute
Implements IBindingSourceMetadata
Inheritance
FromServicesAttribute
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 productModelRequest)
{
    return productModelRequest.Value;
}

Constructors

FromServicesAttribute()

Properties

BindingSource

Applies to