servicestackservicestack-autoquery

ServiceStack - extending AutoQuery Metadata Viewer


ServiceStack's AutoQuery Viewer Plugin allows you to decorate the AutoQueries using AutoQuery metadata attributes. I use the existing Metadata service in AutoQuery to power a front-end and display search queries (similar to the existing AutoQuery Admin Feature)

How can I extend/ add additional properties to the AutoQueryViewerAttribute, such that they are available in the Autoquery metadata service?

Current list of AutoQuery attributes available:

public class AutoQueryViewerAttribute : AttributeBase
{
    public string Title { get; set; }

    public string Description { get; set; }

    public string IconUrl { get; set; }

    public string BrandUrl { get; set; }

    public string BrandImageUrl { get; set; }

    public string TextColor { get; set; }

    public string LinkColor { get; set; }

    public string BackgroundColor { get; set; }

    public string BackgroundImageUrl { get; set; }

    public string DefaultSearchField { get; set; }

    public string DefaultSearchType { get; set; }

    public string DefaultSearchText { get; set; }

    public string DefaultFields { get; set; }
}

I would like to extend the list of AutoQueryViewerAttribute attributes and add two additional properties:

public string SourceDescription { get; set; }

public string SourceApplicationName { get; set; }

Solution

  • You can't extend the [AutoQueryViewer] attribute which is hard coded. The Info on the Attribute is used to populate the Typed AutoQueryMetadataResponse DTO which is what's serialized to provide the AutoQuery metadata services. I've just added Meta String Dictionaries on the MetadataType, AutoQueryViewerConfig, AutoQueryViewerUserInfo, AutoQueryOperation and AutoQueryMetadataResponse DTO in this commit so you can attach additional metadata to the AutoQuery metadata DTOs using the MetadataFilter, e.g:

    Plugins.Add(new AutoQueryMetadataFeature {
        MetadataFilter = response => {
            response.Meta = new Dictionary<string,string> {
               { "SourceApplicationName", "My App" },
               { "SourceDescription", "My App Description" },
            };
        }
    });
    

    This change is available from v4.5.13 that's now available on MyGet.