C#C
C#4y ago
Ben

How would you design a solution to this problem?

unsure what would be the best approach -
I have a SQL table that stores SMS 3rd party providers.
Each provider support different protocols for its integration - (HTTP/SMPP).
According to the provider supported protocol it requires different parameters to be stored.
the HTTP providers stores -
  1. URL endpoint
  2. Api Key
The SMPP providers stores -
  1. IpAddress
  2. Port
  3. Username
  4. Password
Although they are different, they serve the same purpose therefore needs to exist in the same table.
So my question is, how would you handle this scenario both in the db and in the code?

Option 1 -
In the DB have a single table for Provider with such schema -
ProviderId
AccountId
.... (some more columns that are shared between all provider)
Protocol
Custom1 
Custom2
Custom3
Custom4

Protocol is an enum of HTTP/SMPP
And the Custom fields are nvarchar fields that are used according the the Protocol value.
I can select all the providers into a generic Provider class.
Implement an IProvider interface and concrete types - ProviderSMPP and ProviderHTTP
Have a factory method that receives a list of Provider and returns a list of IProvider where I initialize each concrete type using a switch-case on the Protocol field mapping the custom fields into its concrete values.

Option2 -
Break the Provider table.
Leaving the Provider table only with the shared fields, and create a relationship tables for ProviderSMPPCredentials and ProviderHTTPCredentials
And join both tables?


What would you do?
Was this page helpful?