I have a wrappr object that takes a connectionstring and opens up a database and initializes an API before it can be used. After reading Mark Seeman blog post on temporal coupling I've been going crazy over trying to refactor my API so it is clear. I've looked at the .net class SqlConnection and they require Open before you use it, so maybe this type of coupling is unavoidable? I don't know if there is a way to do what I want since it's a wrapper of an existing API but here is what I have. There can only be one connection at a time, else you have to close and restart
public class MyService
{
public MyService(string dataSource)
public void StopRequest()
public void StopAPI()
public Response SendRequest(string request, string pass)
}
You see it requires a datasource string, and starts the API so SendRequests will work but you can only really have one service at a time so unless I save it in some sort of static var or DI singleton, you'd have to call new ..(datasource) everytime even though it's always the same. The only thing that bothers me is if you call stopRequest or StopAPI & then call SendRequest, it will throw an error of course. I think this is avoiding temporal coupling but wanted some thoughts.
Aucun commentaire:
Enregistrer un commentaire