Wrapping an API to support dependency injection

那年仲夏 提交于 2019-12-05 18:49:49

Yes, it's the proper way. The new API interface and proxy class encapsulate the decision of what underlying library to use - a single responsibility.

Yes that is the proper way. I would not put exception handling in your wrapper, all you are doing is creating a class that calls static methods so you can use DI. You want the wrapper to cause the same exceptions under the same circumstances as the API class with the static methods. That way you can use the same exception handling in your method as you would if you were called the class with the static methods. You can then throw the same exceptions under the same circumstances in your mock api class and test the excpetion handling.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!