Вопрос

I have a class that wraps an API. The methods are all API calls. In the constructor it logs in to the API and stores a session token as part of the private class data. All the actual API calls then use that token to make the individual calls.

The API also has a logout call that more or less ends the session. My question is where should I do the logout call? Something with a finalizer? I'm currently using some sort of simple IDisposable implementation but that doesn't really feel like it's the best/proper way.

Это было полезно?

Решение

Your object should implement IDisposable and you should call logout in your Dispose method because this is the expected way to deal with non-memory related resources in .Net.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top