IMetadataProvider Interface |
Namespace: Autofac.Extras.AttributeMetadata
The IMetadataProvider type exposes the following members.
Name | Description | |
---|---|---|
GetMetadata |
Gets metadata pairs for the passed target type.
|
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.
This example shows what a metadata attribute might look like when providing custom metadata:
[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" } }; } }