Created
November 4, 2019 04:04
-
-
Save fmo91/788ca1a24fa98bf45ff969b0308ce8cc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// We will create an enum as a namespace | |
enum Dependencies { | |
// The same pattern that NotificationCenter's Name struct | |
// follows. | |
struct Name: Equatable { | |
let rawValue: String | |
static let `default` = Name(rawValue: "__default__") | |
static func == (lhs: Name, rhs: Name) -> Bool { lhs.rawValue == rhs.rawValue } | |
} | |
// The actual DI Container | |
final class Container { | |
// An array with the dependencies and the keys for them. | |
private var dependencies: [(key: Dependencies.Name, value: Any)] = [] | |
// To use like a singleton. | |
static let `default` = Container() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment