Skip to content

[.NET] Make the stream create functions evolvable #1237

Backlog

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.

  1. 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. One StreamAuth value can be used for many creates.
  2. Replace the auth arguments with one StreamAuth auth argument:
    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
  3. Merge the two internal create paths into one, which selects the OAuth or the headers-provider FFI function. The C FFI doesn't change.
  4. 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions