I'm creating a class Library that can be called by any app that implements it.
This Library basically acts as a shim/facade between an app, and a webapi/signalr server.
There are lots of calls that I would have normally marked as static, but they all require the same basic information (things like user tokens). These can be passed into a static function, but it just seems a bit long winded and messy.
public static async Task<Contact> GetContact(string serverAddress,
string token, string contactID) {...}
I can refactor the whole class to require an instance that would be stored in the App:
API myAPI = new API(string serverAddress, string token);
Contact = await myAPI.Contacts.GetContact(contactID);
public class API {
public API (string serverAddress, string token) {...};
public Contacts Contacts {
get {
if (_contacts == null)
_contacts = new Contacts();
return _contacts;
}
}
}
This works well (especially as I can keep a signalR client running completely inside the instance, raising events when messages come in), but I've had lots of people saying its very wrong, and it doesn't follow any set patterns (warnings of thread safety [do I need it be - await/async != threads], and poor testability).
Unfortunately, other than being told its wrong - I have had no constructive advice.
So my question is: Are there major flaws in this implementation, and if so, what would be the best alternative?
Aucun commentaire:
Enregistrer un commentaire