I have created a minimal ServiceStack 8.4 solution that highlights a NullReferenceError using AutoQuery in a service implementation.
Source code: Minimal project
If I use the required style for .NET 8, the IAutoQuery variable is null in the QueryAlbums service implementation. I need to use the latest coding practice to use the new ServiceStack Jobs feature.
This issue is a follow on from my previous issue:Unable to resolve service for type 'ServiceStack.Jobs.IBackgroundJobs
Code snippets
// Program.cs
// 1. Comment out to make it work (pre .NET8 style)
builder.Services.AddServiceStack(typeof(AutoQueryIssue.ServiceInterface.MyServices).Assembly);
public class AppHost : AppHostBase, IHostingStartup
{
// 2. Uncomment to make it work (pre .NET8 style)
//public AppHost() : base("AutoQueryIssue", typeof(MyServices).Assembly) {}
// 3. Comment out to make it fail (.NET8 style)
public AppHost() : base("AutoQueryIssue") {}
//...
}
public class ChinookServices : Service
{
public IAutoQueryDb AutoQuery { get; set; } = null;
public object Any(QueryAlbums request)
{
using var db = AutoQuery!.GetDb<Albums>(Request);
var q = AutoQuery.CreateQuery(request, Request);
var response = AutoQuery.Execute(request, q, Request);
return response;
}
}
Using the NET8 style, the AutoQuery in ChinookServices is null, causing a NullReferenceError.
Would greatly appreciate a solution.