Skip to content

Commit 6786655

Browse files
authored
Merge pull request #121 from PopPool/refactor/#112-Modulization
[REFACTOR] 3-Layer 기반 클린아키텍처로 모듈화
2 parents 0c69950 + 1d65ee2 commit 6786655

File tree

521 files changed

+5829
-8311
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+5829
-8311
lines changed

Poppool/CoreLayer/Infrastructure/Infrastructure.xcodeproj/project.pbxproj

Lines changed: 443 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
import Foundation
2+
3+
/// 의존성 주입 컨테이너
4+
///
5+
/// 이 컨테이너는 타입 기반으로 의존성을 등록하고 어디서든 안전하게 꺼내 쓸 수 있도록 도와줍니다.
6+
///
7+
/// 앱 시작 시점에 필요한 구현체를 `register(_:_: )`를 통해 등록하고,
8+
/// 이후에는 `resolve(_:)` 메서드를 통해 원하는 타입의 인스턴스를 꺼낼 수 있습니다.
9+
///
10+
/// ## 등록 예시
11+
/// ```swift
12+
/// DIContainer.register(SampleProtocol.self) {
13+
/// SampleImpl()
14+
/// }
15+
/// ```
16+
///
17+
/// ## 사용 예시
18+
/// ```swift
19+
/// // DIContainer의 resolve 메서드를 사용하는 방식
20+
/// let sample: SampleProtocol = DIContainer.resolve(SampleProtocol.self)
21+
/// ```
22+
public final class DIContainer {
23+
private static let container = DIContainer()
24+
25+
private var registrations: [ObjectIdentifier: () -> Any] = [:]
26+
27+
private let resolveQueue = DispatchQueue(label: "resolveQueue")
28+
29+
private init() {}
30+
31+
/// 의존성을 등록합니다.
32+
/// - Parameters:
33+
/// - type: 등록할 프로토콜 또는 클래스 타입
34+
/// - implementation: 해당 타입에 대응되는 구현체를 생성하는 클로저
35+
public static func register<T>(
36+
_ type: T.Type,
37+
_ implementation: @escaping () -> T
38+
) {
39+
container.register(type, implementation)
40+
}
41+
42+
/// 의존성을 꺼내옵니다.
43+
/// - Parameter type: 요청할 타입
44+
/// - Returns: 등록된 타입의 인스턴스
45+
public static func resolve<T>(_ type: T.Type) -> T {
46+
return container.resolve(type)
47+
}
48+
49+
private func register<T>(
50+
_ type: T.Type,
51+
_ implementation: @escaping () -> T
52+
) {
53+
let key = ObjectIdentifier(type)
54+
registrations[key] = { implementation() }
55+
}
56+
57+
private func resolve<T>(_ type: T.Type) -> T {
58+
let key = ObjectIdentifier(type)
59+
60+
guard let registration = registrations[key],
61+
let instance = registration() as? T
62+
else { fatalError("\(type) does not registered") }
63+
64+
return instance
65+
}
66+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
import Foundation
2+
3+
/// 의존성 자동 주입을 위한 프로퍼티 래퍼
4+
///
5+
/// 사용하는 곳에서 `@Dependency`만 붙이면 등록된 구현체가 자동으로 주입됩니다.
6+
///
7+
/// Swift의 프로퍼티 래퍼 특성상 `var`로 선언해야 하지만, 실제 인스턴스는 외부에서 변경할 수 없도록 `private(set)`으로 보호되어 불변성을 유지합니다.
8+
///
9+
/// 사용 예시:
10+
/// ```swift
11+
/// class MyViewModel {
12+
/// @Dependency var sample: SampleProtocol
13+
///
14+
/// func run() {
15+
/// sample.doSomething()
16+
/// }
17+
/// }
18+
/// ```
19+
@propertyWrapper
20+
public final class Dependency<T> {
21+
/// DIContainer에서 꺼내온 실제 인스턴스
22+
public private(set) var wrappedValue: T
23+
24+
/// DIContainer로부터 자동으로 인스턴스를 꺼내와 초기화합니다.
25+
public init() {
26+
self.wrappedValue = DIContainer.resolve(T.self)
27+
}
28+
}

Poppool/Poppool/Presentation/Extension/Date?+.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/Extension/Date?+.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
1-
//
2-
// Date+.swift
3-
// Poppool
4-
//
5-
// Created by SeoJunYoung on 11/30/24.
6-
//
7-
81
import Foundation
92

10-
extension Optional where Wrapped == Date {
3+
public extension Optional where Wrapped == Date {
114
/// `yyyy. MM. dd` 형식으로 날짜를 문자열로 변환합니다.
125
/// - Parameter defaultString: 날짜가 nil일 경우 반환할 기본 문자열 (기본값: 빈 문자열 "")
136
/// - Returns: 형식화된 날짜 문자열 또는 기본 문자열

Poppool/Poppool/Presentation/Extension/Reactive+.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/Extension/Reactive+.swift

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
1-
//
2-
// Reactive+.swift
3-
// MomsVillage
4-
//
5-
// Created by SeoJunYoung on 8/26/24.
6-
//
7-
81
import UIKit
92

103
import RxCocoa
114
import RxSwift
125

13-
extension Reactive where Base: UIViewController {
6+
public extension Reactive where Base: UIViewController {
147

158
var viewDidLoad: ControlEvent<Void> {
169
let source = self.methodInvoked(#selector(Base.viewDidLoad)).map( { _ in })

Poppool/Poppool/Presentation/Extension/String?+.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/Extension/String?+.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import UIKit
22

3-
extension Optional where Wrapped == String {
3+
public extension Optional where Wrapped == String {
44
/// ISO 8601 형식의 문자열을 `Date`로 변환하는 메서드
55
func toDate() -> Date? {
66
guard let self = self else { return nil } // 옵셔널 해제
@@ -41,7 +41,7 @@ extension String {
4141
}
4242
extension String {
4343
/// ISO 8601 형식의 문자열을 `Date`로 변환하는 메서드
44-
func toDate() -> Date? {
44+
public func toDate() -> Date? {
4545
let dateFormatter = DateFormatter()
4646
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
4747

Poppool/Poppool/Presentation/Extension/UIImage+.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/Extension/UIImage+.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import UIKit
99

1010
// UIImage를 색상으로 생성하는 Helper Extension
11-
extension UIImage {
11+
public extension UIImage {
1212
convenience init(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
1313
UIGraphicsBeginImageContext(size)
1414
UIGraphicsGetCurrentContext()?.setFillColor(color.cgColor)
@@ -19,7 +19,7 @@ extension UIImage {
1919
}
2020
}
2121

22-
extension UIImage {
22+
public extension UIImage {
2323
func isBright(threshold: CGFloat = 0.5) -> Bool? {
2424
guard let cgImage = self.cgImage else { return nil }
2525

Poppool/Poppool/Presentation/Extension/UIImageView+.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/Extension/UIImageView+.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import UIKit
22

3-
extension UIImageView {
3+
public extension UIImageView {
44
func setPPImage(path: String?) {
55
guard let path = path else {
66
self.image = UIImage(named: "image_default")
77
return
88
}
9-
let imageURLString = KeyPath.popPoolS3BaseURL + path
9+
let imageURLString = Secrets.popPoolS3BaseURL + path
1010
if let cenvertimageURL = imageURLString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
1111
ImageLoader.shared.loadImage(with: cenvertimageURL, defaultImage: UIImage(named: "image_default"), imageQuality: .origin) { [weak self] image in
1212
DispatchQueue.main.async {
@@ -22,7 +22,7 @@ extension UIImageView {
2222
completion()
2323
return
2424
}
25-
let imageURLString = KeyPath.popPoolS3BaseURL + path
25+
let imageURLString = Secrets.popPoolS3BaseURL + path
2626
if let cenvertimageURL = imageURLString.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
2727
let imageURL = URL(string: cenvertimageURL)
2828
ImageLoader.shared.loadImage(with: cenvertimageURL, defaultImage: UIImage(named: "image_default"), imageQuality: .origin) { [weak self] image in

Poppool/Poppool/Infrastructure/ImageLoader/DiskStorage.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/ImageLoader/DiskStorage.swift

File renamed without changes.

Poppool/Poppool/Infrastructure/ImageLoader/ImageLoader.swift renamed to Poppool/CoreLayer/Infrastructure/Infrastructure/ImageLoader/ImageLoader.swift

File renamed without changes.

0 commit comments

Comments
 (0)