Skip to content

Commit

Permalink
Use IOptionsMonitor to hot reload config (#872)
Browse files Browse the repository at this point in the history
I was operating under the mistaken assumption that `IOptions<T>`
represented the config value at the time of injection and that you only
needed `IOptionsMonitor<T>` if you expected the value to change while
you were holding on to the instance...

Turns out `IOptions<T>` does not reload at all at runtime.
  • Loading branch information
SapiensAnatis authored Jun 13, 2024
1 parent dd290f8 commit d04d5f2
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions DragaliaAPI/DragaliaAPI/ServiceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ IConfiguration configuration
services.AddHttpClient<IPhotonStateApi, PhotonStateApi>(
(sp, client) =>
{
IOptions<PhotonOptions> options = sp.GetRequiredService<IOptions<PhotonOptions>>();
client.BaseAddress = new(options.Value.StateManagerUrl);
IOptionsMonitor<PhotonOptions> options = sp.GetRequiredService<
IOptionsMonitor<PhotonOptions>
>();
client.BaseAddress = new(options.CurrentValue.StateManagerUrl);
}
);
services.AddScoped<IMatchingService, MatchingService>();
Expand Down

0 comments on commit d04d5f2

Please sign in to comment.