Skip to content

jurgowski/ViewerSession

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ViewerSession

A simple dependency injection framework based on Object types. Dependencies are lazily initialized upon reference.

Usage

Dependencies are intended to be defined through extensions.

extension ViewerSession {
    var backend: Backend {
        return provide { 
            Backend() 
        }
    }

    var analytics: PushNotifications {
        return provide {
            Analytics(backend: self.backend)
        }
    }
}

You can define multiple dependencies of the same type via unique keys.

extension ViewerSession {
    var videoCache: FileCache {
        return provide(key: "videos") {
            return FileCache(diskCapacity: 2 * 1024 * 1024 * 1024, // 2 GB
                             cachePath: "video/cache")
        }
    }
}

extension ViewerSession {
    var imageCache: FileCache {
        return provide(key: "images") {
            return FileCache(diskCapacity: 200 * 1024 * 1024, // 200 MB
                             cachePath: "image/cache")
        }
    }
}

About

A simple dependency injection framework.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages