从四处寻找,这就是我正在使用的东西,我认为它可以满足我在问题中所述的需求:
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" } } });
}