Proper way of instantiating Admin Client

What is the best way of using admin client in .NET. We have configured client in app settings.
Is it possible to add this client to ClientProvider for DI as we would like to use it for creating Apps dynamically, but instructions here: https://docs.squidex.io/id-02-documentation/software-development-kits/.net-standard/version-v15-and-later
say that we need app name to add client to DI and we don’t have any apps yet.

How to do this properly?

You can just use a dummy app name. It is more or less only there for convenience and not uses for authentication

1 Like

Omg, working like a charm! Thanks!!!

I can add this to the documentation.

1 Like

After adding the admin client we run into other issue, as I can see that ISquidexClient is using options for getting app name for client, but what we wanted to achieve with AdminClient was to get clients for all other applications.

   // Operation Path: "api/apps/{app}/clients"
      urlBuilder_.Append("api/apps/");
      urlBuilder_.Append(_options.AppName);
      urlBuilder_.Append("/clients");

Is there any way to pass the app name as parameter to adminClient.Apps.GetClientsAsync() ? or to override options value when I’m calling the method?

You have to create a new client per app. Or you create your own client library using OpenAPI.

For backwards compatibility we cannot add an optional app name.

Ok, yes, we wanted to dynamically to get all clients for all apps to create Clients on application startups for that apps.
So it seams that the only way is through our own client?

Or you create just one client per app. If you everything from your root client except the app name, then the authenticator and client factory can be shared as well, so you have only a little bit of allocation costs.

1 Like