Skip to content

Make AddHealthieRedis one method, because two could not be told apart - #41

Merged
ivanvyd merged 1 commit into
mainfrom
fix/redis-registration-overloads
Jul 29, 2026
Merged

Make AddHealthieRedis one method, because two could not be told apart#41
ivanvyd merged 1 commit into
mainfrom
fix/redis-registration-overloads

Conversation

@ivanvyd

@ivanvyd ivanvyd commented Jul 29, 2026

Copy link
Copy Markdown
Owner

AddHealthieRedis("localhost:6379") did not register a Redis connection. It registered "localhost:6379" as a key prefix.

There were two overloads:

AddHealthieRedis(this IServiceCollection, string configuration, string keyPrefix = Default)
AddHealthieRedis(this IServiceCollection, string keyPrefix = Default)

Given a single string argument, C# prefers the second — no optional parameter left unfilled. So the connection string silently became the prefix, no IConnectionMultiplexer was ever registered, and the failure surfaced later as:

System.InvalidOperationException: No service for type
'StackExchange.Redis.IConnectionMultiplexer' has been registered.

That is the exact call the package README documents, so the documented usage was broken.

Why nothing caught it

Every Redis test constructed RedisStateProvider directly. The provider had 15 tests and a 12-writer race; its registration had none. Well-covered code behind an unreachable front door.

The fix

One method, configuration optional. Pass it to have the connection opened; leave it out to use the one the application already registers. There is nothing left for overload resolution to get wrong, and keyPrefix has to be named to be passed alone.

Three new tests go through AddHealthieRedis rather than around it — with a configuration string, with an existing connection, and with only a named prefix. The first fails against the two-overload version:

the shipped two-overload form -> Failed! - Failed: 1

How it was found

By packing all 20 packages into a local feed and consuming them from a console project outside the repositorydotnet add package Healthie.NET.Redis, then actually running it against a real Redis. That is the only thing that exercises what a consumer is handed, and it is a step I had not taken for any package until now.

Verification

466 tests green on net8.0 and net10.0, 0 errors and 0 warnings on a cleaned build.

AddHealthieRedis("localhost:6379") did not register a Redis connection. It
registered "localhost:6379" as a key prefix.

There were two overloads: one taking a configuration string and an optional
prefix, one taking just an optional prefix. Given a single string argument C#
prefers the second -- no optional parameter left unfilled -- so the connection
string silently became the prefix, no IConnectionMultiplexer was registered,
and the failure surfaced later as a missing service. That is the exact call in
the package README, so the documented usage was broken.

Nothing caught it because every test built RedisStateProvider directly. The
provider was well covered and its registration was not covered at all.

One method now, with configuration optional: pass it to have the connection
opened, leave it out to use the one the application already registers. There
is nothing left to resolve between. Three tests go through AddHealthieRedis
rather than around it -- with a configuration string, with an existing
connection, and with only a named prefix -- and the first of those fails
against the two-overload version.

Found by building the packages into a local feed and consuming them from a
project outside the repository, which is the only thing that exercises what
dotnet add package actually hands someone.
@ivanvyd
ivanvyd merged commit 0f79c30 into main Jul 29, 2026
7 of 8 checks passed
@ivanvyd
ivanvyd deleted the fix/redis-registration-overloads branch July 30, 2026 02:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant