Global request filter not firing when trying to call another service/method

I’m obviously doing something wrong here but can’t figure it out. Following this article: ServiceStack How to call my service from code, I’m attempting to call another method (old way, new way, from article) from within a method such as:

    public async Task<object> Post(CreateEnvironment request)
    {
        try
        {
            var environment = request.ConvertTo<Environment>();
            await Db.InsertAsync(environment);
            await HostContext.ServiceController.ExecuteAsync(new SetupEnvironment() { EnvironmentId = environment.Id }, base.Request);
            await Gateway.SendAsync(new SetupEnvironment { EnvironmentId = environment.Id });
            return environment;
        }
        catch (Exception)
        {

            throw;
        }
    }

The “ExecuteAsync” and “SendAsync” are the one’s I’m trying to use but the following code in Startup is not firing:

RegisterTypedRequestFilter<IForEnvironment>((req, res, requestDto) =>
{
    var connectionString = $"Server=localhost;User Id=postgres;Password=asdfsf;Database={requestDto.EnvironmentId:N};Pooling=true;MinPoolSize=0;MaxPoolSize=200";
    req.Items[Keywords.DbInfo] = new ConnectionInfo() { ConnectionString = connectionString };
});

So I’m unable to change the connection string per execution. The RequestDTO is defined as:

public class SetupEnvironment : IReturnVoid, IForEnvironment
{
    public Guid EnvironmentId { get; set; }
}

What am I missing?

The full HTTP Request Pipeline only gets called for HTTP Requests, not for internal requests.

If you’re using the Service Gateway you can add filters to the Gateway* AppHost Filters:

Worked like a charm! Thanks!

1 Like