c# - 如何提供一个接口(interface)来获取和更新key,value?

标签 c#

我正在为我们的应用程序实现一个持久层,并提出了一个设计,我有一个提供程序让客户端更新单个键、值,然后我还有一个事务类,通过它我可以更新多个键,值对。

接口(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,例如 GetValueSetValue

我希望它是一个接口(interface),IStorageProviderITransaction 从中派生。你们会推荐什么?

最佳答案

我相信您打开此线程更多是为了获得确认,而不是不知道该怎么做。当然,为这些方法创建一个通用接口(interface)是可以的,我看不出有什么理由不这样做,只要你把它放在正确的项目中并找到一个合适的名称即可。

关于c# - 如何提供一个接口(interface)来获取和更新key,value?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55148257/

相关文章:

c# - 为什么 Nullable<T>,struct, allows 'null'

c# - itextsharp 渐变背景

c# - 二进制字符串到整数

c# - VB.net 在读取文本文件时读取 ASCII 码

c# - 如何将错误和其他消息从 DAL/业务层向上传递到 UI 层?

c# - 如何通过在 C# 中单击按钮将用户控件加载到面板

C# Windows 窗体混合 VS2013

c# - 在不覆盖的情况下处理 winform 文本框上的箭头键事件

c# - 如何在WPF中闪烁RichTextBox边框和背景色

c# - GroupCollection 上无法访问的可枚举扩展方法