This project is read-only.

Implementing IMetadataAttributeHandler<T>

Apr 25, 2012 at 11:32 AM

I'm trying to implement this interface as follows but I always get a "No component supporting the service..." error. Even when I use a concrete type parameter. What am I doing wrong?

 

    public class AdditionalMetadataAttributeAttributeHandler : IMetadataAttributeHandler<DisplayWithActionLinkAttribute>    {        public AdditionalMetadataAttributeAttributeHandler()        {        }
        public void AlterMetadata(ModelMetadata metadata, CreateMetadataArguments args)        {            if (args.Attributes == null)                return;
            var theAtt = args.Attributes.OfType<DisplayWithActionLinkAttribute>().FirstOrDefault();            if (theAtt != null)                metadata.AdditionalValues[theAtt.AdditionalValuesKey] = theAtt;        }
    }
    [AttributeUsage(AttributeTargets.Property, AllowMultiple = false)]    public abstract class AdditionalMetadataAttribute : Attribute    {        internal string AdditionalValuesKey        {            get { return GetType().FullName; }        }    }
    public class DisplayWithActionLinkAttribute : AdditionalMetadataAttribute    {        public string LinkText { get; set; }        public string JavaScriptClickHandler { get; set; }
        public DisplayWithActionLinkAttribute(string linkText = "edit", string javaScriptClickHandler = null)        {            LinkText = linkText;            JavaScriptClickHandler = javaScriptClickHandler;        }

    }