Closed minhnimble closed 2 years ago
Generic Network Layer
Third party network library
Third party Json Parser
Dependency Injection
class Router{
static func createModule()->UIViewController{
let view = UIViewController()
let presenter = Presenter()
let interactor = Interactor()
........
.........
}
}
after adding dependency injection:
class Router{ static func createModule(view : UIViewController, presenter : Presenter, interactor : Interactor)->UIViewController{
........
.........
}
}
Please let me know your opinion if more improvements can be done here.
I think most of the cases of your responses look good to me and I can't wait to see your improvements applied π. Regarding the following points, I would like to answer to you as follow:
I have used JsonSerializer and JsonDecoder so far. I don't have enough idea about the third party library options. Can you suggest me some names so that I can check. I have very little idea about SwiftyJson.
β I think you misunderstand my question a bit, since my point is mainly about handling JSON:API response format. In case you don't know what it is and why we use it, please feel free to take a look here π.
At the same time, our provided documentations suggest some iOS libraries for handling JSON:API response here and you probably missed that. π
Anyway, what do you think about updating to use a JSON:API parser instead of doing it manually with Codable like now?
Aprt from Routers , Interactors are also creating networking objects inside their methods. So, in both cases I should add dependency injection.
β Yes, it is correct that besides Router for generating the modules, we can also apply the DI for Interactors layer as well. Your update on the constructor for the Router class is indeed the standard way for decoupling components by providing their dependencies from the outside. π
As an additional improvement, you can investigate about using some libraries on iOS for generating the dependencies like Dagger + Hilt or Koin on Android to achieve this. What do you think?
Dependancy injection is added with a commit. Thanks for the valuable suggestion, I will study these.
It is great to see you utilize the VIPER architecture quite well in your code. At the same time, I do have a few small concerns on the following parts that I would love to hear more from you:
It was quite noticeable that there are quite a few improvements can be made on your API Managers layer. As of now, all the network request handlers and parameters are implemented separately per each function in the API Manager classes and there is no Network layer at all. Would you consider to implement a generic Network layer and help the application adapt and retry the requests with more scalability, leading to effortless new extensions in the future like force-upgrade, force-logout, header adaption and SSL pinning down the road in each request?
At the same time, you are using native Apple framework for handling networking instead of any 3rd party library. I am curious if you have any experience with any library out there? And why do you think using native Apple framework is a better choice for the application?
For the data layer, I noticed that you are using Codable and parse JSON API formatted responses manually instead of using a 3rd-party library for handling this task. Why do you think parsing manually like this would be a better choice? And do you think using a JSON API parser library would add more benefits? https://github.com/Shayokh144/SurveyApp/blob/c90b970ecda49fcdcc5471f5ad70cf3c055c97c2/SurveyApp/SurveyApp/src/survey/entity/SurveyEntity.swift#L10-L30
This one is more of a nitpick, but I don't see you apply Dependency Injection in the project at all and you are generating the Module classes and their dependencies directly in the Router class. Do you think it would be better to apply Dependency Injection for this project? If yes, how and where are the most suitable places you think it would be worth applying?