Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support configuration property. #32

Closed
kawoou opened this issue Nov 18, 2018 · 0 comments
Closed

Support configuration property. #32

kawoou opened this issue Nov 18, 2018 · 0 comments
Labels
enhancement New feature or request

Comments

@kawoou
Copy link
Owner

kawoou commented Nov 18, 2018

How to build

Change the Deli configuration file or include it via command line.

application-dev.properties:

environment: dev
server:
    url: https://dev.example.com/

deli.yml:

target:
- App

config:
  App:
    - project: App
    - properties:
      - Resources/Common/*.properties
      - Resources/application-dev.properties # override

command line:

deli build \
  --property "Resource/application-dev.properties" \
  --property "Resources/Common/*.properties"

How to use

1. Package

ServerConfig.swift:

struct ServerConfig: ConfigProperty {
    let target: String = "server"
    let url: String
}

NetworkManager.swift:

final class NetworkManager: Autowired {
    let serverUrl: String

    required init(_ config: ServerConfig) {
        serverUrl = config.url
    }
}

2. Single (without Validate)

NetworkManager.swift:

final class NetworkManager {
    let serverUrl = AppContext.getProperty("server.url") ?? ""
}

3. Single (with Validate)

NetworkManager.swift:

final class NetworkManager: Inject {
    let serverUrl = InjectProperty("server.url")
}

4. Qualifier on Constructor Injection

UserService.swift:

final class UserService: Autowired {
    required init(_/*environment*/ network: NetworkProvider) {
    }
}

5. Qualifier on Inject

LibraryFactory.swift:

final class LibraryFactory: Inject {
    func getBooks() -> [Book] {
        return Inject([Book].self, qualifierBy: "environment")
    }
}

Reference

@kawoou kawoou added the enhancement New feature or request label Nov 18, 2018
@kawoou kawoou closed this as completed Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant