Liftric / DIKit

Dependency Injection Framework for Swift, inspired by KOIN.
MIT License
102 stars 17 forks source link

Resolving by name #8

Closed benjohnde closed 4 years ago

benjohnde commented 6 years ago

Add the ability to resolve components by name

swift2geek commented 5 years ago

@benjohnde which components should be resolvable?

benjohnde commented 5 years ago

It was more like a feature idea. Currently Components are registered with the register method, see here DependencyContainer%2BRegister.swift#L17.

To be resolved later on it uses the tag propery of a Component, cf. Component.swift#L21.

So my idea was to have the possibility to define a name: String to register the Component.

So, for instance that you could do something like the following:

register(with: "backendSlave", Backend() as BackendProtocol)
// and later on:
var backendSlave: BackendProtocol = inject("backendSlave")

Was just some idea I had in mind.