FromServicesAttribute Třída

Definice

Určuje, že parametr nebo vlastnost by měly být vázány pomocí služeb požadavků.

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
Dědičnost
FromServicesAttribute
Atributy
Implementuje

Příklady

V tomto příkladu je implementace IProductModelRequestService zaregistrovaná jako služba. Potom v akci GetProduct je parametr vázán na instanci IProductModelRequestService, která je přeložena ze služeb požadavků.

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

Konstruktory

FromServicesAttribute()

Určuje, že parametr nebo vlastnost by měly být vázány pomocí služeb požadavků.

Vlastnosti

BindingSource

Získá .BindingSource

Platí pro