chore: scaffold out di

Signed-off-by: Alan Brault <alan.brault@visus.io>
This commit is contained in:
2026-08-08 07:53:16 -04:00
parent 4d790cfadb
commit b776b47a62
3 changed files with 45 additions and 0 deletions
@@ -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")
}
}