Click or drag to resize

IMetadataProvider Interface

Defines an attribute that provides custom metadata generation.

Namespace:  Autofac.Extras.AttributeMetadata
Assembly:  Autofac.Extras.AttributeMetadata (in Autofac.Extras.AttributeMetadata.dll) Version: 6.0.0+9ca59cfaf8ca9a019932258d79b859bcf16e8ed2
Syntax
public interface IMetadataProvider

The IMetadataProvider type exposes the following members.

Methods
  NameDescription
Public methodGetMetadata
Gets metadata pairs for the passed target type.
Top
Remarks

The standard attribute metadata mechanism takes the names of public properties from an attribute and creates a dictionary of name/value pairs based on those properties, using that as the metadata for a service.

When you need to provide a more robust attribute-based definition of metadata, you can instead have your metadata attribute implement this interface. Rather than using name/value pairs generated by the properties on your attribute, you can directly provide the metadata key/value pairs to associate with a service.

Examples

This example shows what a metadata attribute might look like when providing custom metadata:

C#
[MetadataAttribute]
[AttributeUsage(AttributeTargets.Class)]
public class ProvidedMetadataAttribute : Attribute, IMetadataProvider
{
  public IDictionary<string, object> GetMetadata(Type targetType)
  {
    return new Dictionary<string, object>()
    {
      { "Key1", "Value1" },
      { "Key2", "Value2" }
    };
  }
}
See Also