-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restructure Project to support Dependency Injection #17
Conversation
@HunteRoi would you be up to take a look at this one? It's a bit bigger than the previous one. |
Fixes #16 |
|
||
/// <summary> | ||
/// The function to decode incoming messages. | ||
/// </summary> | ||
public Action<string, Action<SocketResponse>> Decode { get; set; } = (payload, callback) => callback(JsonConvert.DeserializeObject<SocketResponse>(payload, Client.Instance.SerializerSettings)); | ||
public Action<string, Action<SocketResponse?>>? Decode { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Socket code that uses this asserts that the value is not null with the !
postfix operator. I don't see anything obvious that actually verifies this so it might be a good idea to add something or change this to be non-nullable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's set in the constructor!
realtime-csharp/Realtime/Client.cs
Lines 113 to 135 in cca23d2
public Client(string realtimeUrl, ClientOptions? options = null) | |
{ | |
this.realtimeUrl = realtimeUrl; | |
if (options == null) | |
options = new ClientOptions(); | |
if (options.Encode == null) | |
options.Encode = (payload, callback) => callback(JsonConvert.SerializeObject(payload, SerializerSettings)); | |
if (options.Decode == null) | |
{ | |
options.Decode = (payload, callback) => | |
{ | |
var response = new SocketResponse(SerializerSettings); | |
JsonConvert.PopulateObject(payload, response, SerializerSettings); | |
callback(response); | |
}; | |
} | |
Options = options; | |
subscriptions = new Dictionary<string, Channel>(); | |
} |
This pull represents a restructuring of the entire project to support Dependency Injection and Nullability (ref: supabase-community/supabase-csharp#34 and #16). Unfortunately this introduces some breaking API changes.
Client
is no longer a singleton class.Channel
has a new constructor that usesChannelOptions
Channel.Parameters
has been changed in favor ofChannel.Options
Channel
andPush
are now directly dependent on havingSocket
andSerializerSettings
passed in as opposed to referencing theSingleton
instance.In reality, not much should affect the developer as most of these classes/methods are only being referenced internally by the
Client
. The removal of the Singleton aspect may offer some design changes for those leveraging this library by itself (as opposed to using it only in supabase-csharp.)