Skip to main content

Quick start

Register AarxMaps, add a module, inject its service and make one call. The examples are ASP.NET Core minimal APIs; a console version is at the end.

Store the API key​

Run this in the project folder. AddAarxMaps reads the key from the AarxMaps configuration section below.

dotnet user-secrets init
dotnet user-secrets set "AarxMaps:ApiKey" "YOUR_API_KEY"

Register and call​

Program.cs
using AarxMaps.Core.Extensions;
using AarxMaps.Places.Common.Extensions;
using AarxMaps.Places.Services;
using AarxMaps.Places.Services.Searching;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddAarxMaps(o =>
builder.Configuration.GetSection("AarxMaps").Bind(o));
builder.Services.AddAarxMapsPlaces();

var app = builder.Build();

app.MapGet("/coffee", async (IPlacesService places, CancellationToken ct) => {
var request = new TextRequestBuilder()
.WithTextQuery("coffee in Seattle")
.WithPageSize(5)
.Build();

var result = await places.Search.SearchByTextAsync(request, ct);
return result.Places.Select(p => new { p.PlaceId, p.DisplayName });
});

app.Run();

In a minimal API, a CancellationToken parameter is bound to the request's abort token, so the Google call stops when the client disconnects.

Services you can inject​

Each module registers an entry service that exposes its features as properties (places.Search, routes.Directions), and each feature service on its own. Inject whichever reads better.

ModuleEntry serviceFeature services
PlacesIPlacesServiceIAutocompleteService, ISearchService, IDetailsService
RoutesIRoutesServiceIDirectionsService, IDistanceMatrixService

Without a host​

In a console app or a test, build the container yourself:

Program.cs
using AarxMaps.Core.Extensions;
using AarxMaps.Places.Common.Extensions;
using AarxMaps.Places.Services;
using Microsoft.Extensions.DependencyInjection;

var apiKey = Environment.GetEnvironmentVariable("GOOGLE_MAPS_API_KEY")!;

var services = new ServiceCollection()
.AddAarxMaps(o => o.ApiKey = apiKey)
.AddAarxMapsPlaces();

await using var provider = services.BuildServiceProvider();
var places = provider.GetRequiredService<IPlacesService>();

Without a host, the configuration is validated the first time a service is resolved instead of at startup.

Next steps​