Skip to content

Instantly share code, notes, and snippets.

@fmo91
Created November 4, 2019 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fmo91/788ca1a24fa98bf45ff969b0308ce8cc to your computer and use it in GitHub Desktop.
Save fmo91/788ca1a24fa98bf45ff969b0308ce8cc to your computer and use it in GitHub Desktop.
// 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