Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support user-arguments. #4

Closed
kawoou opened this issue Apr 25, 2018 · 1 comment
Closed

Support user-arguments. #4

kawoou opened this issue Apr 25, 2018 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@kawoou
Copy link
Owner

kawoou commented Apr 25, 2018

Payload:

struct UserPayload: Payload {
    let userID: String

    required init(with argument: (userID: String)) {
        self.userID = argument.userID
    }
}

AutowiredFactory:

class UserViewModel: AutowiredFactory {
    required init(
        _ testService: TestService,
        _ userService: UserService,
        payload: UserPayload
    ) {
        self.testService = testService
        self.userID = payload.userID
    }
}

//-----------------------------------------------------------

class UserView: UIView, Inject {
    let viewModel: UserViewModel

    init(userID: String) {
        viewModel = Inject(UserViewModel.self, with: (userID: userID))
    }
}

LazyAutowiredFactory:

class UserViewModel: LazyAutowiredFactory {
    func inject(
        _ testService: TestService,
        _ userService: UserService,
        payload: UserPayload
    ) {
        self.testService = testService
        self.userID = payload.userID
    }
    required init() {}
}

//-----------------------------------------------------------

class UserView: UIView, Inject {
    let viewModel: UserViewModel

    init(userID: String) {
        viewModel = Inject(UserViewModel.self, with: (userID: userID))
    }
}

If specified as a Factory, automatically operates as a prototype scope.

@kawoou kawoou self-assigned this Apr 25, 2018
@kawoou kawoou added the enhancement New feature or request label Apr 25, 2018
@kawoou kawoou removed their assignment Apr 25, 2018
@kawoou
Copy link
Owner Author

kawoou commented Apr 25, 2018

@devxoul I would like to add AutowiredFactory, LazyAutowiredFactory for this feature.

@kawoou kawoou self-assigned this Apr 28, 2018
kawoou added a commit that referenced this issue May 1, 2018
kawoou added a commit that referenced this issue May 7, 2018
kawoou added a commit that referenced this issue May 7, 2018
kawoou added a commit that referenced this issue May 7, 2018
kawoou added a commit that referenced this issue May 11, 2018
kawoou added a commit that referenced this issue May 11, 2018
@kawoou kawoou closed this as completed May 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant