Skip to content

Commit 3cb45f0

Browse files
committed
Define repo ID with unbound type TId
1 parent 92ab653 commit 3cb45f0

File tree

8 files changed

+30
-19
lines changed

8 files changed

+30
-19
lines changed

IntegrationEngine.Core/Storage/DatabaseRepository.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Linq;
55
using System.Text;
66
using System.Threading.Tasks;
7+
using IntegrationEngine.Model;
78

89
namespace IntegrationEngine.Core.Storage
910
{
@@ -21,23 +22,23 @@ public DatabaseRepository(IntegrationEngineContext db)
2122
this.db = db;
2223
}
2324

24-
public IEnumerable<TItem> SelectAll<TItem>() where TItem : class
25+
public IEnumerable<TItem> SelectAll<TItem>() where TItem : class, IHasLongId
2526
{
2627
return db.Set<TItem>().ToList<TItem>();
2728
}
2829

29-
public TItem SelectById<TItem>(object id) where TItem : class
30+
public TItem SelectById<TItem>(object id) where TItem : class, IHasLongId
3031
{
3132
return db.Set<TItem>().Find(id);
3233

3334
}
3435

35-
public TItem Insert<TItem>(TItem item) where TItem : class
36+
public TItem Insert<TItem>(TItem item) where TItem : class, IHasLongId
3637
{
3738
return db.Set<TItem>().Add(item);
3839
}
3940

40-
public TItem Update<TItem>(TItem item) where TItem : class
41+
public TItem Update<TItem>(TItem item) where TItem : class, IHasLongId
4142
{
4243
db.Set<TItem>().Attach(item);
4344
db.Entry(item).State = EntityState.Modified;

IntegrationEngine.Core/Storage/ElasticsearchRepository.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public TItem Update<TItem>(TItem item) where TItem : class, IHasStringId
4848
);
4949
return response as TItem;
5050
}
51-
51+
5252
public void Delete<TItem>(object id) where TItem : class
5353
{
5454
ElasticClient.Delete<TItem>(x => x.Id(id.ToString()));

IntegrationEngine.Core/Storage/IDatabaseRepository.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using System;
1+
using IntegrationEngine.Model;
2+
using System;
23
using System.Data.Entity;
34

45
namespace IntegrationEngine.Core.Storage
56
{
6-
public interface IDatabaseRepository : IRepository, IDisposable
7+
public interface IDatabaseRepository : IRepository<IHasLongId>, IDisposable
78
{
89
void Save();
910
void SetState<TItem>(TItem item, EntityState entityState) where TItem : class;

IntegrationEngine.Core/Storage/IElasticsearchRepository.cs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,7 @@
44

55
namespace IntegrationEngine.Core.Storage
66
{
7-
public interface IElasticsearchRepository : IRepository
8-
{
9-
new IEnumerable<TItem> SelectAll<TItem>() where TItem : class, IHasStringId;
10-
new TItem SelectById<TItem>(object id) where TItem : class, IHasStringId;
11-
new TItem Update<TItem>(TItem item) where TItem : class, IHasStringId;
12-
new TItem Insert<TItem>(TItem item) where TItem : class, IHasStringId;
13-
}
7+
public interface IElasticsearchRepository : IRepository<IHasStringId>
8+
{}
149
}
1510

IntegrationEngine.Core/Storage/IRepository.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77

88
namespace IntegrationEngine.Core.Storage
99
{
10-
public interface IRepository
10+
public interface IRepository<TId>
1111
{
12-
IEnumerable<TItem> SelectAll<TItem>() where TItem : class;
13-
TItem SelectById<TItem>(object id) where TItem : class;
14-
TItem Insert<TItem>(TItem item) where TItem : class;
15-
TItem Update<TItem>(TItem item) where TItem : class;
12+
IEnumerable<TItem> SelectAll<TItem>() where TItem : class, TId;
13+
TItem SelectById<TItem>(object id) where TItem : class, TId;
14+
TItem Insert<TItem>(TItem item) where TItem : class, TId;
15+
TItem Update<TItem>(TItem item) where TItem : class, TId;
1616
void Delete<TItem>(object id) where TItem : class;
1717
bool Exists<TItem>(object id) where TItem : class;
1818
bool IsServerAvailable();

IntegrationEngine.Model.net40/IntegrationEngine.Model.net40.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@
103103
<Compile Include="..\IntegrationEngine.Model\IHealthStatus.cs">
104104
<Link>IHealthStatus.cs</Link>
105105
</Compile>
106+
<Compile Include="..\IntegrationEngine.Model\IHasLongId.cs">
107+
<Link>IHasLongId.cs</Link>
108+
</Compile>
106109
</ItemGroup>
107110
<ItemGroup>
108111
<None Include="packages.config" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
using System;
2+
3+
namespace IntegrationEngine.Model
4+
{
5+
public interface IHasLongId
6+
{
7+
long Id { get; set; }
8+
}
9+
}
10+

IntegrationEngine.Model/IntegrationEngine.Model.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@
7373
<Compile Include="IHealthStatus.cs" />
7474
<Compile Include="TriggerPropertyExtension.cs" />
7575
<Compile Include="TriggerStateDescription.cs" />
76+
<Compile Include="IHasLongId.cs" />
7677
</ItemGroup>
7778
<ItemGroup>
7879
<None Include="package.nuspec">

0 commit comments

Comments
 (0)