我正在为我们的应用程序实现一个持久层,并提出了一个设计,我有一个提供程序让客户端更新单个键、值,然后我还有一个事务类,通过它我可以更新多个键,值对。
接口(interface)是:
public interface IStorageProvider
{
bool GetValue<T>(string key, out T value);
T GetOrCreateValue<T>(string key) where T : new();
bool SetValue<T>(string key, T value);
ITransaction Transaction();
}
public interface ITransaction : IDisposable
{
event EventHandler<TransactionEventArgs> CommitSucceeded;
event EventHandler<TransactionEventArgs> CommitFailed;
bool GetValue<T>(string key, out T value);
bool SetValue<T>(string key, T value);
void Commit();
}
我不喜欢提供者和事务有类似的 API,例如 GetValue
和 SetValue
。
我希望它是一个接口(interface),IStorageProvider
和 ITransaction
从中派生。你们会推荐什么?
最佳答案
我相信您打开此线程更多是为了获得确认,而不是不知道该怎么做。当然,为这些方法创建一个通用接口(interface)是可以的,我看不出有什么理由不这样做,只要你把它放在正确的项目中并找到一个合适的名称即可。
关于c# - 如何提供一个接口(interface)来获取和更新key,value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55148257/