Share via


FromServicesAttribute Class

Definition

Specifies that a parameter or property 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)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
[System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
[<System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)>]
type FromServicesAttribute = class
    inherit Attribute
    interface IBindingSourceMetadata
[<System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)>]
type FromServicesAttribute = class
    inherit Attribute
    interface IBindingSourceMetadata
    interface IFromServiceMetadata
[<System.AttributeUsage(System.AttributeTargets.Parameter | System.AttributeTargets.Property, AllowMultiple=false, Inherited=true)>]
type FromServicesAttribute = class
    inherit Attribute
    interface IBindingSourceMetadata
    interface IFromServiceMetadata
Public Class FromServicesAttribute
Inherits Attribute
Implements IBindingSourceMetadata
Public Class FromServicesAttribute
Inherits Attribute
Implements IBindingSourceMetadata, IFromServiceMetadata
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

Gets the BindingSource.

Applies to