Repository navigation
Description
SDK
.NET
Description
The number of stream create functions in ZerobusSdk grows with every new auth mode and data format. Today there are 12: 3 formats (generic, JSON, Protocol Buffers) × 2 auth modes (OAuth, headers provider) × 2 (sync, async) (dotnet/src/Zerobus/ZerobusSdk.cs:90-396). The auth mode is part of the method name (...WithHeadersProvider) and of the positional arguments (clientId, clientSecret), so it multiplies the count. A new format such as Avro takes it to 16, and a new auth mode such as a personal access token to 24.
Proposed Solution
Make auth one parameter, and keep one create function per format (plus its Async twin). The multiplexed streams in #1124 use this shape first.
- Add one closed auth type. Its constructor is not public, so users can't subclass it, and new cases can be added later:
public abstract class StreamAuth { private protected StreamAuth() { } public static StreamAuth OAuth(string clientId, string clientSecret) => ...; public static StreamAuth Headers(IHeadersProvider provider) => ...; // later, for example: public static StreamAuth PersonalAccessToken(string token) => ...; }
ToString()must not show the client secret. OneStreamAuthvalue can be used for many creates. - Replace the auth arguments with one
StreamAuth authargument:CreateStream(TableProperties table, StreamAuth auth, StreamConfigurationOptions? options = null) CreateJsonStream(string tableName, StreamAuth auth, StreamConfigurationOptions? options = null) CreateProtoStream(string tableName, byte[] descriptor, StreamAuth auth, StreamConfigurationOptions? options = null) // + the three Async versions
- Merge the two internal create paths into one, which selects the OAuth or the headers-provider FFI function. The C FFI doesn't change.
- Keep the 12 current functions as
[Obsolete]one-line wrappers that point to the replacement, and remove them in 1.0.0. The change is additive.
Result: 6 public create functions instead of 12. A new auth mode adds one StreamAuth factory and no create function. A new format adds 2 functions (sync and async).
Additional Context
- One create per format stays, because each format returns its own typed stream (
JsonZerobusStream,ProtoZerobusStream). Fewer functions would need a builder or generics. - A call that passes literal nulls for every argument, such as
CreateJsonStream("table", null, null), matches both the old and the new overload and no longer compiles. Typed arguments are not affected. - Work that adds formats (for example Avro) should use the new shape, or land after this change.
Activity