Skip to content

Commit ee60c78

Browse files
author
Jeff Treuting
committed
Remove old aspect stuff and added custom contexts
1 parent 3f21363 commit ee60c78

File tree

9 files changed

+98
-191
lines changed

9 files changed

+98
-191
lines changed

SharpRepository.Logging.NLog/NLogRepositoryLogger.cs

Lines changed: 45 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using SharpRepository.Repository;
33
using SharpRepository.Repository.Aspects;
44
using NLog;
5-
using SharpRepository.Repository.Specifications;
65

76
namespace SharpRepository.Logging.NLog
87
{
@@ -67,6 +66,51 @@ public override void OnSaveExecuted<T, TKey>(RepositoryActionContext<T, TKey> co
6766
_logger.Debug(String.Format("Saved {0} entity", typeof(T).Name));
6867
}
6968

69+
public override void OnGetExecuting<T, TKey>(RepositoryGetContext<T, TKey> context)
70+
{
71+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
72+
73+
_logger.Debug(String.Format("{0} Executing Get: Id = {1}", typeDisplay, context.Id));
74+
}
75+
76+
public override void OnGetExecuted<T, TKey>(RepositoryGetContext<T, TKey> context)
77+
{
78+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
79+
80+
_logger.Debug(String.Format("{0} Executed Get: Id = {1}", typeDisplay, context.Id));
81+
_logger.Debug(String.Format("{0} Results: {1} Cache Used: {2}", typeDisplay, context.NumberOfResults, context.Repository.CacheUsed));
82+
}
83+
84+
public override void OnGetAllExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context)
85+
{
86+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
87+
88+
_logger.Debug(String.Format("{0} Executing GetAll", typeDisplay));
89+
}
90+
91+
public override void OnGetAllExecuted<T, TKey>(RepositoryQueryContext<T, TKey> context)
92+
{
93+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
94+
95+
_logger.Debug(String.Format("{0} Executed GetAll", typeDisplay));
96+
_logger.Debug(String.Format("{0} Results: {1} Cache Used: {2}", typeDisplay, context.NumberOfResults, context.Repository.CacheUsed));
97+
}
98+
99+
public override void OnFindExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context)
100+
{
101+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
102+
103+
_logger.Debug(String.Format("{0} Executing Find: {1}", typeDisplay, context.Specification.Predicate));
104+
}
105+
106+
public override void OnFindExecuted<T, TKey>(RepositoryQueryContext<T, TKey> context)
107+
{
108+
var typeDisplay = RepositoryTypeDisplay(context.Repository);
109+
110+
_logger.Debug(String.Format("{0} Executed Find: {1}", typeDisplay, context.Specification.Predicate));
111+
_logger.Debug(String.Format("{0} Results: {1} Cache Used: {2}", typeDisplay, context.NumberOfResults, context.Repository.CacheUsed));
112+
}
113+
70114
public override void OnFindAllExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context)
71115
{
72116
var typeDisplay = RepositoryTypeDisplay(context.Repository);

SharpRepository.Repository/Aspects/IRepositoryAspect.cs

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 3 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
using System;
22
using System.Linq.Expressions;
3-
using SharpRepository.Repository.Queries;
4-
using SharpRepository.Repository.Specifications;
53

64
namespace SharpRepository.Repository.Aspects
75
{
86
public abstract class RepositoryActionBaseAttribute : Attribute
97
{
108
public virtual void OnInitialized<T, TKey>(RepositoryActionContext<T, TKey> context) where T : class
119
{
12-
1310
}
1411

1512
public virtual bool OnAddExecuting<T, TKey>(T entity, RepositoryActionContext<T, TKey> context) where T : class
@@ -49,27 +46,24 @@ public virtual void OnSaveExecuted<T, TKey>(RepositoryActionContext<T, TKey> con
4946
}
5047

5148
/* Queries */
52-
public virtual bool OnGetExecuting<T, TKey>(RepositoryGetContext<T, TKey> context) where T : class
49+
public virtual void OnGetExecuting<T, TKey>(RepositoryGetContext<T, TKey> context) where T : class
5350
{
54-
return true;
5551
}
5652

5753
public virtual void OnGetExecuted<T, TKey>(RepositoryGetContext<T, TKey> context) where T : class
5854
{
5955
}
6056

61-
public virtual bool OnGetAllExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
57+
public virtual void OnGetAllExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
6258
{
63-
return true;
6459
}
6560

6661
public virtual void OnGetAllExecuted<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
6762
{
6863
}
6964

70-
public virtual bool OnFindExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
65+
public virtual void OnFindExecuting<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
7166
{
72-
return true;
7367
}
7468

7569
public virtual void OnFindExecuted<T, TKey>(RepositoryQueryContext<T, TKey> context) where T : class
@@ -84,42 +78,4 @@ public virtual void OnFindAllExecuted<T, TKey>(RepositoryQueryContext<T, TKey> c
8478
{
8579
}
8680
}
87-
88-
public class RepositoryActionContext<T, TKey> where T : class
89-
{
90-
public RepositoryActionContext(IRepository<T, TKey> repository)
91-
{
92-
Repository = repository;
93-
}
94-
95-
public IRepository<T, TKey> Repository { get; set; }
96-
}
97-
98-
public class RepositoryQueryContext<T, TKey> : RepositoryActionContext<T, TKey> where T : class
99-
{
100-
public RepositoryQueryContext(IRepository<T, TKey> repository, ISpecification<T> specification, IQueryOptions<T> queryOptions, int numberOfResults = 0)
101-
: base(repository)
102-
{
103-
Specification = specification;
104-
QueryOptions = queryOptions;
105-
NumberOfResults = numberOfResults;
106-
}
107-
108-
public ISpecification<T> Specification { get; set; }
109-
public IQueryOptions<T> QueryOptions { get; set; }
110-
public int NumberOfResults { get; set; }
111-
}
112-
113-
public class RepositoryGetContext<T, TKey> : RepositoryActionContext<T, TKey> where T : class
114-
{
115-
public RepositoryGetContext(IRepository<T, TKey> repository, T id, int numberOfResults)
116-
: base(repository)
117-
{
118-
Id = id;
119-
NumberOfResults = numberOfResults;
120-
}
121-
122-
public T Id { get; set; }
123-
public int NumberOfResults { get; set; }
124-
}
12581
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace SharpRepository.Repository.Aspects
2+
{
3+
public class RepositoryActionContext<T, TKey> where T : class
4+
{
5+
public RepositoryActionContext(IRepository<T, TKey> repository)
6+
{
7+
Repository = repository;
8+
}
9+
10+
public IRepository<T, TKey> Repository { get; set; }
11+
}
12+
}

SharpRepository.Repository/Aspects/RepositoryAspect.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

SharpRepository.Repository/Aspects/RepositoryAspectCollection.cs

Lines changed: 0 additions & 68 deletions
This file was deleted.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
namespace SharpRepository.Repository.Aspects
2+
{
3+
public class RepositoryGetContext<T, TKey> : RepositoryActionContext<T, TKey> where T : class
4+
{
5+
public RepositoryGetContext(IRepository<T, TKey> repository, T id, int numberOfResults)
6+
: base(repository)
7+
{
8+
Id = id;
9+
NumberOfResults = numberOfResults;
10+
}
11+
12+
public T Id { get; set; }
13+
public int NumberOfResults { get; set; }
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using SharpRepository.Repository.Queries;
2+
using SharpRepository.Repository.Specifications;
3+
4+
namespace SharpRepository.Repository.Aspects
5+
{
6+
public class RepositoryQueryContext<T, TKey> : RepositoryActionContext<T, TKey> where T : class
7+
{
8+
public RepositoryQueryContext(IRepository<T, TKey> repository, ISpecification<T> specification, IQueryOptions<T> queryOptions, int numberOfResults = 0)
9+
: base(repository)
10+
{
11+
Specification = specification;
12+
QueryOptions = queryOptions;
13+
NumberOfResults = numberOfResults;
14+
}
15+
16+
public ISpecification<T> Specification { get; set; }
17+
public IQueryOptions<T> QueryOptions { get; set; }
18+
public int NumberOfResults { get; set; }
19+
}
20+
}

SharpRepository.Repository/SharpRepository.Repository.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
<Reference Include="System.Runtime.Caching" />
3838
</ItemGroup>
3939
<ItemGroup>
40-
<Compile Include="Aspects\IRepositoryAspect.cs" />
41-
<Compile Include="Aspects\RepositoryAspect.cs" />
42-
<Compile Include="Aspects\RepositoryAspectCollection.cs" />
4340
<Compile Include="Aspects\RepositoryActionBaseAttribute.cs" />
41+
<Compile Include="Aspects\RepositoryActionContext.cs" />
42+
<Compile Include="Aspects\RepositoryGetContext.cs" />
43+
<Compile Include="Aspects\RepositoryQueryContext.cs" />
4444
<Compile Include="Caching\CachingStrategyBase.cs" />
4545
<Compile Include="Caching\ICachePrefixManager.cs" />
4646
<Compile Include="Caching\MultiServerCachePrefixManager.cs" />

0 commit comments

Comments
 (0)