-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d22a03
commit 39f40fc
Showing
14 changed files
with
168 additions
and
7 deletions.
There are no files selected for viewing
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
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
18 changes: 18 additions & 0 deletions
18
Projects/App/Source/Application/DI/Assembly/FlowAssembly.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// FlowAssembly.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import Swinject | ||
import FlowKit | ||
|
||
class FlowAssembly: Assembly { | ||
|
||
func assemble(container: Container) { | ||
container.register(FlowProvider.self) { _ in | ||
FlowProvider(rootView: MainView()) | ||
} | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
Projects/App/Source/Application/DI/Assembly/ViewModelAssembly.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
// | ||
// ViewModelAssembly.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import Swinject | ||
|
||
class ViewModelAssembly: Assembly { | ||
|
||
func assemble(container: Container) { | ||
container.register(MainViewModel.self) { _ in | ||
MainViewModel() | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// | ||
// Inject.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import Swinject | ||
|
||
@propertyWrapper | ||
public struct Inject<T> { | ||
|
||
public let wrappedValue: T = { | ||
if let value = DependencyProvider.shared.container.resolve(T.self) { | ||
return value | ||
} else { | ||
fatalError("Injection error: \(T.self)") | ||
} | ||
}() | ||
|
||
public init() { } | ||
} |
31 changes: 31 additions & 0 deletions
31
Projects/App/Source/Application/DI/Injection/InjectObject.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// InjectObject.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import SwiftUI | ||
import Swinject | ||
|
||
@propertyWrapper | ||
public struct InjectObject<T>: DynamicProperty where T: ObservableObject { | ||
|
||
@StateObject private var object: T = { | ||
if let value = DependencyProvider.shared.container.resolve(T.self) { | ||
return value | ||
} else { | ||
fatalError("Injection error: \(T.self)") | ||
} | ||
}() | ||
|
||
public var wrappedValue: T { | ||
object | ||
} | ||
|
||
public var projectedValue: ObservedObject<T>.Wrapper { | ||
$object | ||
} | ||
|
||
public init() { } | ||
} |
27 changes: 27 additions & 0 deletions
27
Projects/App/Source/Application/DI/Provider/DependencyProvider.swift
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// DependencyProvider.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import Swinject | ||
|
||
class DependencyProvider { | ||
|
||
static let shared = DependencyProvider() | ||
|
||
let container = Container() | ||
let assembler: Assembler | ||
|
||
init() { | ||
Container.loggingFunction = nil | ||
assembler = Assembler( | ||
[ | ||
FlowAssembly(), | ||
ViewModelAssembly() | ||
], | ||
container: container | ||
) | ||
} | ||
} |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// | ||
// MainViewModel.swift | ||
// DodamDodam | ||
// | ||
// Created by Mercen on 3/13/24. | ||
// | ||
|
||
import Combine | ||
import FlowKit | ||
|
||
class MainViewModel: ObservableObject { | ||
|
||
@Inject var flow: FlowProvider | ||
} |
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
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
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
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
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