Custom AutoQuery Data Implementation change

Has there been a change to the requirements for Custom AutoQuery Data Implementations?

I had the following which works fine in 5.1.0, but recently updated to 5.13 and now returns an ArgumentNullException “Value cannot be null. Parameter name: req” when using the service.

It’s a Windows Self Hosted service, using .NET Framework 4.72 - I can put it up on Github if needed… but it is pretty simple.

namespace ServiceStackSelfHostedTest
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }

        protected override void OnStart(string[] args)
        {
            var appHost = new AppHost();

            appHost.Init().Start("http://localhost/");
        }

        protected override void OnStop()
        {
        }
    }

    public class AppHost : AppSelfHostBase
    {
        public AppHost() : base("WidgetAPI", typeof(WidgetServices).Assembly)
        {
        }

        public override void Configure(Funq.Container container)
        {
            this.Routes.Add(typeof(WidgetQuery), "/Widgets", "GET", "A queryable list of widgets", "");

            this.Plugins.Add(new AutoQueryFeature() { EnableAutoQueryViewer = true });

            this.Plugins.Add(new AutoQueryDataFeature());

            this.Plugins.Add(new ServiceStack.Admin.AdminFeature());
        }
    }

    public class WidgetQuery : QueryData<WidgetItem> { }
    public class WidgetItem
    {
        virtual public string Description { get; set; }        
    }

    public class WidgetServices : Service
    {
        public IAutoQueryData AutoQuery { get; set; }

        public object Get(WidgetQuery query)
        {
            WidgetItemList widgets = new WidgetItemList();
            widgets.Add(new WidgetItem() { Description = "test 1"} );
            widgets.Add(new WidgetItem() { Description = "test 2" });

            var q = AutoQuery.CreateQuery(query, Request, db: new MemoryDataSource<WidgetItem>(widgets, query, Request));
            return AutoQuery.Execute(query, q);
        }
    }

    public class WidgetItemList : System.Collections.Generic.List<WidgetItem>
    {

    }
}

Yeah db has to be passed to AutoQuery.Execute() as well:

var db = new MemoryDataSource<WidgetItem>(widgets, query, Request);
var q = AutoQuery.CreateQuery(query, Request, db);
return AutoQuery.Execute(query, q, db);
1 Like

Yep - that works now… thanks!

1 Like