I'm starting a new asp.net mvc core project and for my infrastructure layer I'd like to use WebAPI as this layer should be usable in other solutions besides this one.
I'm not really experienced with that and at the moment I'm thinking of having 2 contracts and 2 implementations for them in the infrastructure layer e.g:
public interface IUserService
{
int Add(UserDTO user);
UserDTO Update(UserDTO user);
UserDTO Remove(UserDTO user);
UserDTO Get(int id);
}
public interface IUserWebService
{
int Add(UserDTO user);
UserDTO Update(UserDTO user);
UserDTO Remove(UserDTO user);
UserDTO Get(int id);
}
Where the first one is the one that will be injected in the controllers in the presentation layer and the second one is the one that will be implemented by the WebAPI.
Then the implementation goes like this, the web api simply implements the IUserWebService
along with the crud operations just as usual and then another type is created UserService
which implements IUserService
, which will serve only as a wrapper for the webapi implementation. The reason being invoking the webapi is a bit lengthy and this way that part of the logic will be isolated in this extra class.
This seems reasonable to me, but I'm not sure if it's the proper way to go, any advises would be welcome.