Calling Service Internally a Common Use Case for Autoquery?

Is it a common use of autoquery to use it internally within a service instead of using Ormlite directly?

Or it’s not recommended/a bad idea?

For example:

namespace MYProject.ServiceInterface;

public class MyServices : Service
{
    public object Any(Hello request)
    {
       var res = this.Gateway.Send<QueryCustomers>()

       //do logic...
    
        return new HelloResponse { Result = $"Hello, {request.Name}!" };
    }
}

It’s just like calling any other service internally, the benefit of using the Service Gateway is that it can continue to work if you decide to later move it to an an external service however in this case it’s just adds a lot of unnecessary overhead vs calling OrmLite directly, e.g. vs Db.Select<Customer>().

Also you can call the AutoQuery API directly, as the done in the Custom AutoQuery Implementations if you need access to some built-in AutoQuery functionality which would also have less overhead than using the Service Gateway:

public class MyServices : Service
{
    public IAutoQueryDb AutoQuery { get; set; }

    public object Any(Hello request)
    {
       var query = new QueryCustomers { ... };
        var q = AutoQuery.CreateQuery(query, base.Request, Db);
        var res = AutoQuery.Execute(query, q, base.Request, Db);

       //do logic...
    
        return new HelloResponse { Result = $"Hello, {request.Name}!" };
    }
}

Thank you for this. My use case is more complicated than the example I gave.

In another of your answers, I read that you try to avoid extracting logic from service classes to external classes. Is that the case?

Even if that’s your recommendation, I would like to know if it’s possible to inject these:

  • The service gateway
  • The default db connection
  • A named db connection

In an external class called CustomerSyncer that is not a service class.

In Configure.AppHost I’ve been able to register other dependencies for CustomerSyncer using:

container.RegisterAutoWired();

But I haven’t figured out how to inject the gateway of the current service, the default db connection and a named connection.

Thanks again.

Not from the IOC, resolve them from your Service class at runtime then pass it as arguments to your external class.