Skip to content

Commit

Permalink
[DEV][Added resolver for di]
Browse files Browse the repository at this point in the history
  • Loading branch information
developersancho committed Feb 26, 2022
1 parent 9ebeda8 commit ff36ff9
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 4 deletions.
12 changes: 12 additions & 0 deletions SwiftRorty.iOS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
E2AD779A27CAC1E8006565C2 /* RestClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AD779927CAC1E8006565C2 /* RestClient.swift */; };
E2AD779C27CAC242006565C2 /* RestClientErrors.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AD779B27CAC242006565C2 /* RestClientErrors.swift */; };
E2AD779E27CACD8D006565C2 /* CharacterListDto.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AD779D27CACD8D006565C2 /* CharacterListDto.swift */; };
E2AD77A127CAD8E1006565C2 /* AppModule.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2AD77A027CAD8E1006565C2 /* AppModule.swift */; };
E2D5A98327C96E3E0017DA32 /* APIMethod.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D5A98227C96E3E0017DA32 /* APIMethod.swift */; };
E2D5A98527C974010017DA32 /* APIClient.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D5A98427C974010017DA32 /* APIClient.swift */; };
E2D5A98727C9771D0017DA32 /* APIClientImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2D5A98627C9771D0017DA32 /* APIClientImpl.swift */; };
Expand Down Expand Up @@ -125,6 +126,7 @@
E2AD779927CAC1E8006565C2 /* RestClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestClient.swift; sourceTree = "<group>"; };
E2AD779B27CAC242006565C2 /* RestClientErrors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RestClientErrors.swift; sourceTree = "<group>"; };
E2AD779D27CACD8D006565C2 /* CharacterListDto.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CharacterListDto.swift; sourceTree = "<group>"; };
E2AD77A027CAD8E1006565C2 /* AppModule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppModule.swift; sourceTree = "<group>"; };
E2D5A98227C96E3E0017DA32 /* APIMethod.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIMethod.swift; sourceTree = "<group>"; };
E2D5A98427C974010017DA32 /* APIClient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClient.swift; sourceTree = "<group>"; };
E2D5A98627C9771D0017DA32 /* APIClientImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APIClientImpl.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -199,6 +201,7 @@
E2291D3127A5E908006D3FD8 /* SwiftRorty.iOS */ = {
isa = PBXGroup;
children = (
E2AD779F27CAD8CA006565C2 /* di */,
E267D17527C9188300254746 /* component */,
E2291D6327A5E992006D3FD8 /* core */,
E2291D5C27A5E941006D3FD8 /* data */,
Expand Down Expand Up @@ -471,6 +474,14 @@
path = network;
sourceTree = "<group>";
};
E2AD779F27CAD8CA006565C2 /* di */ = {
isa = PBXGroup;
children = (
E2AD77A027CAD8E1006565C2 /* AppModule.swift */,
);
path = di;
sourceTree = "<group>";
};
FE5D0614452C9D5795CE3E9B /* Pods */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -745,6 +756,7 @@
E2D5A98B27C977EF0017DA32 /* Decoder.swift in Sources */,
E2D5A98D27C97AC20017DA32 /* APIEndpoint.swift in Sources */,
E2555C0727A87252007E5266 /* GetCharacters.swift in Sources */,
E2AD77A127CAD8E1006565C2 /* AppModule.swift in Sources */,
E2991AB927AC76FA00BF4B9A /* Location.swift in Sources */,
E2555BFF27A87181007E5266 /* PageInfo.swift in Sources */,
E2991ABD27AC777300BF4B9A /* CharacterResponse.swift in Sources */,
Expand Down
5 changes: 4 additions & 1 deletion SwiftRorty.iOS/data/remote/CharacterService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@

import Foundation
import Combine
import Resolver

protocol CharacterService {
func getCharacters(page: Int) -> AnyPublisher<CharacterListDto, Error>
}

class CharacterServiceImpl: CharacterService {

private let restClient = RestClientImpl()
//private let restClient = RestClientImpl()

@Injected private var restClient: RestClient

func getCharacters(page: Int) -> AnyPublisher<CharacterListDto, Error> {
//requestGetCharacters(page: page).map { $0.toCharacterDtoList() }.eraseToAnyPublisher()
Expand Down
4 changes: 3 additions & 1 deletion SwiftRorty.iOS/data/repository/CharacterRepository.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import Foundation
import Combine
import Resolver

class CharacterRepository {
private let remoteService: CharacterService = CharacterServiceImpl()
//private let remoteService: CharacterService = CharacterServiceImpl()
@Injected private var remoteService: CharacterService

// init(_ remoteService: CharacterService = CharacterServiceImpl()) {
// self.remoteService = remoteService
Expand Down
36 changes: 36 additions & 0 deletions SwiftRorty.iOS/di/AppModule.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// AppModule.swift
// SwiftRorty.iOS
//
// Created by developersancho on 27.02.2022.
//

import Foundation
import Resolver

extension Resolver: ResolverRegistering {
public static func registerAllServices() {
defaultScope = .graph
registerSingletons()
registerRemote()
registerRepository()
registerDomain()
}

private static func registerSingletons() {
register { RestClientImpl() as RestClient }.scope(.application)
}

private static func registerRemote() {
register { CharacterServiceImpl() as CharacterService }
}

private static func registerRepository() {
register { CharacterRepository() }
}

private static func registerDomain() {
register { GetCharacters() }
}

}
4 changes: 3 additions & 1 deletion SwiftRorty.iOS/domain/GetCharacters.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

import Foundation
import Combine
import Resolver

class GetCharacters {
private let repository: CharacterRepository = CharacterRepository()
//private let repository: CharacterRepository = CharacterRepository()
@Injected private var repository: CharacterRepository

// init(_ repository: CharacterRepository = CharacterRepository()) {
// self.repository = repository
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import Foundation
import UIKit
import Combine
import Resolver

class CharactersViewModel: ObservableObject {
// private let getCharacters: GetCharacters = GetCharacters()
Expand Down Expand Up @@ -37,7 +38,8 @@ class CharactersViewModel: ObservableObject {
// }.store(in: &disposables)
// }

private let getCharacters: GetCharacters = GetCharacters()
//private let getCharacters: GetCharacters = GetCharacters()
@Injected private var getCharacters: GetCharacters

@Published var charactersList : [CharacterDto] = []
private var cancelables = [AnyCancellable]()
Expand Down

0 comments on commit ff36ff9

Please sign in to comment.