kawoou / deli Goto Github PK
View Code? Open in Web Editor NEWDeli is an easy-to-use Dependency Injection(DI).
License: MIT License
Deli is an easy-to-use Dependency Injection(DI).
License: MIT License
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"
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
}
}
NetworkManager.swift:
final class NetworkManager {
let serverUrl = AppContext.getProperty("server.url") ?? ""
}
NetworkManager.swift:
final class NetworkManager: Inject {
let serverUrl = InjectProperty("server.url")
}
UserService.swift:
final class UserService: Autowired {
required init(_/*environment*/ network: NetworkProvider) {
}
}
LibraryFactory.swift:
final class LibraryFactory: Inject {
func getBooks() -> [Book] {
return Inject([Book].self, qualifierBy: "environment")
}
}
In case, projects are managed by integrating them into separate modules.
Don't instantiated the DeliFactory class yourself.
Provides load methods via AppContext.
AppDelegate.swift:
import Deli
import OtherModule1
import OtherModule2
class AppDelegate {
var window: UIWindow?
let container = AppContext.load([
DeliFactory.self,
OtherModule1.DeliFactory.self,
OtherModule2.DeliFactory.self
])
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
return true
}
}
I want to change to this format.
deli.yml:
target:
- Sample
- GitHubSearch
- Survey
config:
Sample:
include:
- Tests/DeliTests/DeliSample
exclude:
- Tests/DeliTests/DeliSample/DeliFactory.swift
output: Tests/DeliTests/DeliSample
GitHubSearch:
project: Examples/GitHubSearch/GitHubSearch
output: GitHubSearch/DeliFactory.swift
Survey:
project: Examples/Survey/Survey.xcodeproj
output: Survey/DeliFactory.swift
Need to change the style of error messages in a way that Xcode understands.
{FILE_PATH}:{LINE}:{CHARACTER}: {warning | error}: {MESSAGE}
Update Config file that supports specifies the name of output class.
Do not need to build all the branches.
Set up to build only master, develop and PR.
deli build
throw below error when don't have a deli.yml file:
⛔️ Error: The file “DeliFactory.swift” couldn’t be opened because there is no such file.
I want to modify it so that we can specify qualifier in Autowired protocol.
But, a good way to easy-use has not thought yet.
The lifecycle of UICollectionViewCell is managed by UICollectionView.
In such a case, dependency injection must be possible.
This rules in #4:
class PhotoCollectionViewCell: UICollectionViewCell, Injectable {
func inject(_ userService: Dependency<UserService>, _ userID: Argument<String>) {
...
}
}
//-----------------------------------------------------------
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
...
cell.inject(with: (userID))
...
return cell
}
We temporarily used the name "Injectable". Is there a good naming?
Payload:
struct UserPayload: Payload {
let userID: String
required init(with argument: (userID: String)) {
self.userID = argument.userID
}
}
AutowiredFactory:
class UserViewModel: AutowiredFactory {
required init(
_ testService: TestService,
_ userService: UserService,
payload: UserPayload
) {
self.testService = testService
self.userID = payload.userID
}
}
//-----------------------------------------------------------
class UserView: UIView, Inject {
let viewModel: UserViewModel
init(userID: String) {
viewModel = Inject(UserViewModel.self, with: (userID: userID))
}
}
LazyAutowiredFactory:
class UserViewModel: LazyAutowiredFactory {
func inject(
_ testService: TestService,
_ userService: UserService,
payload: UserPayload
) {
self.testService = testService
self.userID = payload.userID
}
required init() {}
}
//-----------------------------------------------------------
class UserView: UIView, Inject {
let viewModel: UserViewModel
init(userID: String) {
viewModel = Inject(UserViewModel.self, with: (userID: userID))
}
}
If specified as a Factory, automatically operates as a prototype scope.
The Test Mode
function is inconvenient for writing test code.
Therefore, want to improve the ModuleFactory so that it can be simplified.
class SomeControllerTests: QuickSpec {
override func spec() {
super.spec()
var sut: SomeController!
var mockUserService: MockUserService!
var mockFriendService: MockFriendService!
let testModule = ModuleFactory()
testModule.register(MockUserService.self) { MockUserService() }
.link(UserService.self)
testModule.register(MockFriendService.self) { MockFriendService() }
.link(FriendService.self)
beforeEach {
AppContext.shared.load(testModule, priority: .high)
}
afterEach {
AppContext.shared.reset()
AppContext.shared.unload(testModule)
}
describe("SomeController") {
beforeEach {
sut = AppContext.shared.get(SomeController.self)
mockUserService = AppContext.shared.get(MockUserService.self)
mockFriendService = AppContext.shared.get(MockFriendService.self)
}
...
}
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.