0

ビットを処理する .net フレームワーク コンソール コードを開発しています。エンティティの生成が完了した後、エンティティを保持するリポジトリを実装して、エンティティを再度生成する必要がないようにしたいと考えています。まず、リポジトリでデータ ファイルをローカル ファイルシステムに書き込み、後で必要に応じてより堅牢な (RMDBS) バックエンドを配置します。もちろん、リポジトリの単体テスト/モックもできるようにしたいです。

github でSharpRepositoryプロジェクトを見つけました。独自の実装を展開するのではなく、それを活用したいと考えています。XMLRepository クラスは、私が実装したいクラスのように見えますが、方法がわかりません。wiki には、それに関するドキュメントが含まれていません。

図書館XmlRepositoryの利用方法は?SharpRepository

4

2 に答える 2

0

突っついたところから、これは私が使用しているものであり、質問に記載されている私のニーズを満たすと思います:

using Microsoft.Extensions.Caching.Memory;
using SharpRepository.Repository;
using SharpRepository.XmlRepository;
using SharpRepository.Repository.Caching;
using SharpRepository.EfRepository;

public class MyEntity
{
    public DateTime EventDateTime;
    public Dictionary<string, string> attributes = new Dictionary<string, string>();
}
static void Main(string[] args)
{
    MemoryCache memoryCache = new MemoryCache(new MemoryCacheOptions());
    InMemoryCachingProvider inMemoryCachingProvider = new InMemoryCachingProvider(memoryCache);
    IRepository<MyEntity> myRepo = new XmlRepository<MyEntity>(@"C:\temp\MyLocalRepo", new StandardCachingStrategy<MyEntity>(inMemoryCachingProvider));

    // When I am ready to further develop the data layer, I can swap the repo out for a different one
    //IRepository<MyEntity> myRepo = new EfRepository<MyEntity>(new System.Data.Entity.DbContext("myConnectionString"));

    // And my logic that interacts with the repository will still work
    myRepo.Add(new MyEntity { EventDateTime = new DateTime(2019, 06, 16), attributes = new Dictionary<string, string> { { "WithAttrbutes", "AndTheirValues" } } });
}
于 2019-06-16T16:35:58.137 に答える