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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user