1

I've done the Plugins.Add(new AutoQueryFeature { MaxLimit = 100 }); and used it in startup Configure Method.

enter image description here

enter image description here

This is dto inherites QueryDb

enter image description here

I keep encountering AutoQuery is null and NullReferenceException thrown at AutoQuery.CreateQuery() Method. And CallStacks can not show ExternalCodes. I have no ideas where it gone wrong by referring to TechStacks Project.

enter image description here

enter image description here

The project references ServiceStack.Core 5.7.0

I'm able to get AutoQuery by using the below code.

var autoquery = TryResolve<IAutoQueryDb>() 

enter image description here

Steven Li
  • 754
  • 1
  • 8
  • 16

1 Answers1

1

None of your code samples show the 3 important things required for AutoQuery, the AutoQueryFeature plugin registration in your AppHost’s Configure(), the definition of your Service class that implements the Service base class, the public IAutoQueryDb AutoQuery { get; set; } public property.

If they’re configured correctly the IAutoQueryDb dependency should be injected.

mythz
  • 141,670
  • 29
  • 246
  • 390
  • the plugin AutoQueryFeature in AppHost Configure and the inherits ServiceStack.Service and public IAutoQueryDb AutoQuery { get; set; } are there. I've updated the screenshots. I do not know where it goes wrong, AutoQuery is still null. – Steven Li Jul 04 '20 at 08:15
  • Can't identify the issue from the screenshots, can you try seeing if you can resolve it from the IOC directly, e.g. `var autoquery = TryResolve()`. Note: your DefaultContentType is invalid, if you want JSON it should instead be: `DefaultContentType = MimeTypes.Json`. – mythz Jul 04 '20 at 08:20
  • Thanks @mythz `var autoquery = TryResolve()` is working. Noted with `DefaultContentType = MimeTypes.Json`. Why I can't use the `public IAutoQueryDb AutoQuery { get; set; }` public property. I updated the screenshot above. is there anyway to troubleshoot ? – Steven Li Jul 04 '20 at 08:58
  • It appears something is preventing (or overriding) the IoC property injection, not identifiable from just this description. If you can put together a stand-alone repro on GitHub using ServiceStack v5.9 I can take a look. – mythz Jul 04 '20 at 09:03
  • I'm using ServiceStack.Core v5.7.0 will it be the cause ? because I need to renew my license if using ServiceStack v5.9. – Steven Li Jul 04 '20 at 09:06
  • You won’t need a license for the repro, but need to confirm that’s it an issue with the latest version – mythz Jul 04 '20 at 09:08
  • BTW why are you using ServiceStack.Core, are you using ASP.NET Core on the .NET Framework? – mythz Jul 04 '20 at 09:12
  • Thanks @mythz. I will give a try for the latest assembly. I'm using asp.net core. not .NET Framework. So I instinctively thought the ServiceStack.Core should be the right assembly. So I should change to ServiceStack ? – Steven Li Jul 04 '20 at 09:30
  • Yes, the .Core packages is only for [ASP.NET Core on the .NET Framework](https://docs.servicestack.net/templates-corefx) use the normal packages for .NET Core, this could be the issue if you’re mixing packages – mythz Jul 04 '20 at 09:34
  • NullReferenceException thrown at AutoQuery.CreateQuery() Method. it is still the same even I uses servicestack 5.9.0. – Steven Li Jul 04 '20 at 11:05
  • Ok post a stand-alone repro on GitHub and I’ll take a look – mythz Jul 04 '20 at 12:15
  • 1
    I spent some time doing a repro. but it turns out totally fine. Finally I find out the autoquery problem associates with `services.AddSingleton();services.AddSingleton();` after I commented out the IHostedService, AutoQuery is working fine. – Steven Li Jul 05 '20 at 11:33