共用方式為


FromServicesAttribute 類別

定義

指定應該使用要求服務來系結參數或屬性。

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
繼承
FromServicesAttribute
屬性
實作

範例

在此範例中,IProductModelRequestService 的實作會註冊為服務。 然後在 GetProduct 巨集指令中,參數會系結至從要求服務解析的 IProductModelRequestService 實例。

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

建構函式

FromServicesAttribute()

指定應該使用要求服務來系結參數或屬性。

屬性

BindingSource

取得 BindingSource

適用於