Created
February 14, 2012 11:22
-
-
Save damianh/1825986 to your computer and use it in GitHub Desktop.
Storage (Repository Discussion)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Guard clauses / contracts omitted for berivity | |
//Thread safety not considered. | |
public interface IKeyValueStore | |
{ | |
void Add<T>(string key, T item); | |
void AddOrUpdate<T>(string key, T item); | |
bool Remove(string key); | |
bool TryGetValue<T>(string key, out T item); | |
} | |
public class IsolatedStorageSettingsKeyValueStore : IKeyValueStore | |
{ | |
private readonly IsolatedStorageSettings _isolatedStorageSettings; | |
public IsolatedStorageSettingsKeyValueStore(IsolatedStorageSettings isolatedStorageSettings) | |
{ | |
_isolatedStorageSettings = isolatedStorageSettings; | |
} | |
public void Add<T>(string key, T item) | |
{ | |
_isolatedStorageSettings.Add(key, item); | |
} | |
public void AddOrUpdate<T>(string key, T item) | |
{ | |
T storedItem; | |
if(TryGetValue(key, out storedItem)) | |
{ | |
if (!item.Equals(storedItem)) | |
{ | |
_isolatedStorageSettings[key] = item; | |
} | |
} | |
_isolatedStorageSettings.Add(key, item); | |
} | |
public bool Remove(string key) | |
{ | |
return _isolatedStorageSettings.Remove(key); | |
} | |
public bool TryGetValue<T>(string key, out T item) | |
{ | |
return _isolatedStorageSettings.TryGetValue(key, out item); | |
} | |
} | |
public class TypicalNinjectModule : NinjectModule | |
{ | |
public override void Load() | |
{ | |
Bind<IKeyValueStore>().To<IsolatedStorageSettingsKeyValueStore>(); | |
Bind<IsolatedStorageSettings>().ToMethod(ctx => IsolatedStorageSettings.ApplicationSettings); | |
} | |
} |
You can incorporate it.
…On 14 February 2012 12:48, Dean McDonnell < ***@***.*** > wrote:
Just wanted to check, do you mind if I feed this back into the
WinPhoneKit.Storage project or would you like to do it?
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/1825986
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The problem with these sort of abstractions over arbitrary 'storage' is that they invariably become leaky.