We have a dependency to a third-party service which exposes a gigantic interface of which we only need like 3 methods. Additionally, the interface changes frequently...
I've decided to wrap the interface in a class in our project and only expose the methods that we need.
But I'm unsure how I should handle the return values...
The interface returns an object of type Storage
. We internally have a type StorageModel
which is our internal representation of a Storage
.
What would you return in the mapper: Storage
or StorageModel
?
We have a DataService StorageService
which get a dependency of the wrapper injected.
Currently I'm doing it basically like this:
public class StorageService
{
private readonly IExternalStorageWrapper externalStorageWrapper;
public StorageService(IExternalStorageWrapper externalStorageWrapper)
{
this.externalStorageWrapper = externalStorageWrapper;
}
public StorageModel GetStorage(int storageId)
{
return this.externalStorageWrapper.GetStorage(storageId).ConvertToStorageModel();
}
}
public class ExternalStorageWrapper : IExternalStorageWrapper
{
public Storage GetStorage(int storageId)
{
using(var ext = new ExternalStorage())
{
return ext.GetStorage(storageId);
}
}
}
What would you say:
- Is it good like above, that the wrapper returns the external
Storage
object and the internalStorageService
returns the internalStorageModel
? - Or would you return a
StorageModel
in the wrapper already?