✅ Client creation design dilema
I created a design dilema in my head. I have created a library, which utilizes the tcp client, that has a client with private constructors. One parameterless and one that takes in an
IFrameReader
and an NetworkStream
(the IFrameReader is a custom Pipeline I made that adapts to any type of stream you give it).
If you do a parameter-less construction, you have to connect to your device with a host and port that you pass into a ConnectAsync(string host, int port)
method.
If you construct the client with the IFrameReader and NetworkStream, you do not use ConnectAsync as the data it receives from the IFrameReader you pass in is up to you to interface properly with.
I have built this into a factory pattern:
I'm wondering if I should instead have it designed like this:
or something like an optional options param in the ctor
or if it even matters at all and I should just stick with my factory pattern.1 Reply
The thing I dislike most about the fluent .With() design is it makes the client mutable, which its really not supposed to be. So perhaps I strike that as an option
So I'm really torn between factory pattern and options pattern. But with options pattern you could inject options straight into it with DI like
services.Configure<MyClientOptions>()
🤔
Im gonna use the options pattern