Skip to content

9. Configuration

Michal Motyčka edited this page Apr 4, 2025 · 1 revision

GenerateEndpointCallsAsExtensionMethods

This setting makes Ridge generate all clients as extension methods on the ApiClient class. This means that instead of needing a separate client for each controller, you only need one ApiClient.

Example:

// GenerateEndpointCallsAsExtensionMethods turned off
var examplesControllerClient = new ExamplesControllerClient(client, webApplicationFactory.Services);
var response = await examplesControllerClient.ReturnGivenNumber(10);

// GenerateEndpointCallsAsExtensionMethods turned on
var apiClient = new ApiClient(client, webApplicationFactory.Services);
var response = await apiClient.ReturnGivenNumber(10);

ApiClient is an almost empty placeholder class. It comes from the Ridge.AspNetCore namespace in the RidgeDotNet.AspNetCore package.

To turn on this setting, add this to your .csproj file:

<PropertyGroup>
    <Ridge_GenerateEndpointCallsAsExtensionMethods>enable</Ridge_GenerateEndpointCallsAsExtensionMethods>
</PropertyGroup>

Endpoints

Turning on this setting also adds some special behavior. If you have a controller with only one action, and that action's name is one of the following: "Execute", "ExecuteAsync", "HandleAsync", "Handle", "Invoke", or "InvokeAsync", then the generated method gets its name from the controller name, and the action name is ignored.

For example, for this controller:

[ApiController]
[Route("[controller]")]
[GenerateClient]
public class TransformEndpointAndMethodNameEndpoint : ControllerBase
{
    // Action name like "Execute" will be ignored for the generated method name
    public void Execute()
    {
    }
}

Ridge will generate an extension method called TransformEndpointAndMethodName (using the controller's name).

Clone this wiki locally