c# - How do I pass a platform-specific string (a path) in MvvmCross -
i have database stored in different places depending on platform. example, xamarin.mac, database stored in @executable_path/../resources/my.db. right viewmodel handles initializing database, , i'm happy leave there. however, need pass path , see is
var startup = mvx.resolve<imvxappstart>(); startup.start (); in appdelegate. in mvx have been using registersingleton , resolve, i'm not sure should using simple string (should have imydbpath , mydbpath interface , class?) looking elegant solution. thanks!
if you're using mvvmcross-sqlite-net plugin. once it's registered, either manually or bootstrap there 2 interfaces can resolve:
isqliteconnectionfactory or isqliteconnectionfactoryex
when resolve isqliteconnectionfactory you'll able call create(string address) passing path database. path give create not platform specific, meaning, create figure out platform specific base path you.
private isqliteconnection createfiledb(sqliteconnectionoptions options) { if (string.isnullorwhitespace(options.address)) throw new argumentexception(properties.resources.createfiledbinvalidaddress); var path = options.basepath ?? getdefaultbasepath(); string filepath = localpathcombine(path, options.address); return createsqliteconnection(filepath, options.storedatetimeasticks); } so pass mydatabase.db or data/mydatabase.db on supported platforms , should resolve base path you.
Comments
Post a Comment