-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathRepository.cs
More file actions
39 lines (30 loc) · 982 Bytes
/
Repository.cs
File metadata and controls
39 lines (30 loc) · 982 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using System;
using System.Collections.Generic;
using TaskTracker.Common.DataStrategy;
namespace TaskTracker.Common.Repository
{
public abstract class Repository<T> : IRepository<T> where T : class
{
protected ICacheStrategy<T> cacheStrategy;
protected IDbStrategy<T> dbStrategy;
public Repository(ICacheStrategy<T> cacheStrategy, IDbStrategy<T> dbStrategy)
{
this.cacheStrategy = cacheStrategy;
this.dbStrategy = dbStrategy;
}
public T GetById(string id)
{
var item = this.cacheStrategy.Get(id);
if (item != null)
{
return item;
}
item = this.dbStrategy.GetById(id);
this.cacheStrategy.InsertOrUpdate(item);
return item;
}
public abstract IEnumerable<T> GetAll();
public abstract T Delete(string id);
public abstract T InsertOrUpdate(T entity);
}
}