英語で読む

次の方法で共有


FromServicesAttribute クラス

定義

要求サービスを使用してパラメーターまたはプロパティをバインドすることを指定します。

C#
[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
C#
[System.AttributeUsage(System.AttributeTargets.Parameter, AllowMultiple=false, Inherited=true)]
public class FromServicesAttribute : Attribute, Microsoft.AspNetCore.Http.Metadata.IFromServiceMetadata, Microsoft.AspNetCore.Mvc.ModelBinding.IBindingSourceMetadata
C#
[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
継承
FromServicesAttribute
属性
実装

この例では、IProductModelRequestService の実装がサービスとして登録されています。 次に、GetProduct アクションで、 パラメーターは要求サービスから解決される IProductModelRequestService のインスタンスにバインドされます。

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

コンストラクター

FromServicesAttribute()

要求サービスを使用してパラメーターまたはプロパティをバインドすることを指定します。

プロパティ

BindingSource

BindingSource を取得します。

適用対象

製品 バージョン
ASP.NET Core 1.0, 1.1, 2.0, 2.1, 2.2, 3.0, 3.1, 5.0, 6.0, 7.0, 8.0, 9.0