chore: scaffold out di
Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
+23
@@ -63,3 +63,26 @@ public actor DefaultForecastRepository: ForecastRepository {
|
||||
return record
|
||||
}
|
||||
}
|
||||
|
||||
extension DefaultForecastRepository {
|
||||
public static func makeDefault(inMemory: Bool = false) throws -> DefaultForecastRepository {
|
||||
let schema = Schema([WeatherResponseRecord.self, DailyForecastRecord.self])
|
||||
let configuration: ModelConfiguration = if inMemory {
|
||||
ModelConfiguration(schema: schema, isStoredInMemoryOnly: true)
|
||||
} else {
|
||||
ModelConfiguration(schema: schema, url: try storeURL())
|
||||
}
|
||||
let container = try ModelContainer(for: schema, configurations: [configuration])
|
||||
return DefaultForecastRepository(modelContainer: container)
|
||||
}
|
||||
|
||||
private static func storeURL() throws -> URL {
|
||||
let applicationSupportDirectory = try FileManager.default.url(
|
||||
for: .applicationSupportDirectory,
|
||||
in: .userDomainMask,
|
||||
appropriateFor: nil,
|
||||
create: true
|
||||
)
|
||||
return applicationSupportDirectory.appending(path: "ForecastCache.store")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import TempestasDomain
|
||||
import TempestasInfrastructure
|
||||
import TempestasPresentation
|
||||
|
||||
@MainActor
|
||||
final class AppComposition {
|
||||
private let forecastRepository: ForecastRepository
|
||||
|
||||
init(inMemory: Bool = false) {
|
||||
guard let forecastRepository = try? DefaultForecastRepository.makeDefault(inMemory: inMemory) else {
|
||||
fatalError("Failed to create the forecast cache store")
|
||||
}
|
||||
|
||||
self.forecastRepository = forecastRepository
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,12 @@ import SwiftData
|
||||
|
||||
@main
|
||||
struct TempestasApp: App {
|
||||
private let composition: AppComposition
|
||||
|
||||
init() {
|
||||
self.composition = AppComposition()
|
||||
}
|
||||
|
||||
var sharedModelContainer: ModelContainer = {
|
||||
let schema = Schema([
|
||||
Item.self,
|
||||
|
||||
Reference in New Issue
Block a user