Swinject: Resolve using one protocol from protocol composition

Created on 9 Mar 2017  路  2Comments  路  Source: Swinject/Swinject

Hello. Can I do something like this?

typealias UserSession = UserLogin & UserLogout

container.register(UserSession.self) { r in
     UserSessionManager(network: r.resolve(LoginService.self)!,
                       keychain: r.resolve(KeychainWrapper.self)!)
}

and then call

r.resolve(UserLogin.self)!

question

Most helpful comment

Hi @vidrilla,

Swinject is matching exact types, so just like that it would not work. However, you could add:

container.register(UserLogin.self) { r in r.resolve(UserSession.self)! }
container.register(UserLogout.self) { r in r.resolve(UserSession.self)! }

to make resolution of partial protocols work

All 2 comments

Hi @vidrilla,

Swinject is matching exact types, so just like that it would not work. However, you could add:

container.register(UserLogin.self) { r in r.resolve(UserSession.self)! }
container.register(UserLogout.self) { r in r.resolve(UserSession.self)! }

to make resolution of partial protocols work

@vidrilla, please feel free to reopen this issue if the issue is not resolved.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

oronbz picture oronbz  路  3Comments

phillippbertram picture phillippbertram  路  8Comments

alynmuntean picture alynmuntean  路  6Comments

igorkotkovets picture igorkotkovets  路  7Comments

sialcasa picture sialcasa  路  5Comments