Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 13ce0b9

Browse files
author
nbasakuragi
committedApr 2, 2014
First commit
0 parents  commit 13ce0b9

13 files changed

+730
-0
lines changed
 

‎.gitattributes

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto
3+
4+
# Custom for Visual Studio
5+
*.cs diff=csharp
6+
*.sln merge=union
7+
*.csproj merge=union
8+
*.vbproj merge=union
9+
*.fsproj merge=union
10+
*.dbproj merge=union
11+
12+
# Standard to msysgit
13+
*.doc diff=astextplain
14+
*.DOC diff=astextplain
15+
*.docx diff=astextplain
16+
*.DOCX diff=astextplain
17+
*.dot diff=astextplain
18+
*.DOT diff=astextplain
19+
*.pdf diff=astextplain
20+
*.PDF diff=astextplain
21+
*.rtf diff=astextplain
22+
*.RTF diff=astextplain

‎.gitignore

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
#################
2+
## Eclipse
3+
#################
4+
5+
*.pydevproject
6+
.project
7+
.metadata
8+
bin/
9+
tmp/
10+
*.tmp
11+
*.bak
12+
*.swp
13+
*~.nib
14+
local.properties
15+
.classpath
16+
.settings/
17+
.loadpath
18+
19+
# External tool builders
20+
.externalToolBuilders/
21+
22+
# Locally stored "Eclipse launch configurations"
23+
*.launch
24+
25+
# CDT-specific
26+
.cproject
27+
28+
# PDT-specific
29+
.buildpath
30+
31+
32+
#################
33+
## Visual Studio
34+
#################
35+
36+
## Ignore Visual Studio temporary files, build results, and
37+
## files generated by popular Visual Studio add-ons.
38+
39+
# User-specific files
40+
*.suo
41+
*.user
42+
*.sln.docstates
43+
44+
# Build results
45+
46+
[Dd]ebug/
47+
[Rr]elease/
48+
x64/
49+
build/
50+
[Bb]in/
51+
[Oo]bj/
52+
53+
# MSTest test Results
54+
[Tt]est[Rr]esult*/
55+
[Bb]uild[Ll]og.*
56+
57+
*_i.c
58+
*_p.c
59+
*.ilk
60+
*.meta
61+
*.obj
62+
*.pch
63+
*.pdb
64+
*.pgc
65+
*.pgd
66+
*.rsp
67+
*.sbr
68+
*.tlb
69+
*.tli
70+
*.tlh
71+
*.tmp
72+
*.tmp_proj
73+
*.log
74+
*.vspscc
75+
*.vssscc
76+
.builds
77+
*.pidb
78+
*.log
79+
*.scc
80+
81+
# Visual C++ cache files
82+
ipch/
83+
*.aps
84+
*.ncb
85+
*.opensdf
86+
*.sdf
87+
*.cachefile
88+
89+
# Visual Studio profiler
90+
*.psess
91+
*.vsp
92+
*.vspx
93+
94+
# Guidance Automation Toolkit
95+
*.gpState
96+
97+
# ReSharper is a .NET coding add-in
98+
_ReSharper*/
99+
*.[Rr]e[Ss]harper
100+
101+
# TeamCity is a build add-in
102+
_TeamCity*
103+
104+
# DotCover is a Code Coverage Tool
105+
*.dotCover
106+
107+
# NCrunch
108+
*.ncrunch*
109+
.*crunch*.local.xml
110+
111+
# Installshield output folder
112+
[Ee]xpress/
113+
114+
# DocProject is a documentation generator add-in
115+
DocProject/buildhelp/
116+
DocProject/Help/*.HxT
117+
DocProject/Help/*.HxC
118+
DocProject/Help/*.hhc
119+
DocProject/Help/*.hhk
120+
DocProject/Help/*.hhp
121+
DocProject/Help/Html2
122+
DocProject/Help/html
123+
124+
# Click-Once directory
125+
publish/
126+
127+
# Publish Web Output
128+
*.Publish.xml
129+
*.pubxml
130+
131+
# NuGet Packages Directory
132+
## TODO: If you have NuGet Package Restore enabled, uncomment the next line
133+
#packages/
134+
135+
# Windows Azure Build Output
136+
csx
137+
*.build.csdef
138+
139+
# Windows Store app package directory
140+
AppPackages/
141+
142+
# Others
143+
sql/
144+
*.Cache
145+
ClientBin/
146+
[Ss]tyle[Cc]op.*
147+
~$*
148+
*~
149+
*.dbmdl
150+
*.[Pp]ublish.xml
151+
*.pfx
152+
*.publishsettings
153+
154+
# RIA/Silverlight projects
155+
Generated_Code/
156+
157+
# Backup & report files from converting an old project file to a newer
158+
# Visual Studio version. Backup files are not needed, because we have git ;-)
159+
_UpgradeReport_Files/
160+
Backup*/
161+
UpgradeLog*.XML
162+
UpgradeLog*.htm
163+
164+
# SQL Server files
165+
App_Data/*.mdf
166+
App_Data/*.ldf
167+
168+
#############
169+
## Windows detritus
170+
#############
171+
172+
# Windows image file caches
173+
Thumbs.db
174+
ehthumbs.db
175+
176+
# Folder config file
177+
Desktop.ini
178+
179+
# Recycle Bin used on file shares
180+
$RECYCLE.BIN/
181+
182+
# Mac crap
183+
.DS_Store
184+
185+
186+
#############
187+
## Python
188+
#############
189+
190+
*.py[co]
191+
192+
# Packages
193+
*.egg
194+
*.egg-info
195+
dist/
196+
build/
197+
eggs/
198+
parts/
199+
var/
200+
sdist/
201+
develop-eggs/
202+
.installed.cfg
203+
204+
# Installer logs
205+
pip-log.txt
206+
207+
# Unit test / coverage reports
208+
.coverage
209+
.tox
210+
211+
#Translations
212+
*.mo
213+
214+
#Mr Developer
215+
.mr.developer.cfg

‎Decorator/LoggerRepository.cs

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using System;
2+
using DecoratorProxyPattern.Repository;
3+
4+
namespace DecoratorProxyPattern.Decorator
5+
{
6+
public class LoggerRepository<T> : IRepository<T>
7+
{
8+
private readonly IRepository<T> _decorated;
9+
public LoggerRepository(IRepository<T> decorated)
10+
{
11+
_decorated = decorated;
12+
}
13+
private void Log(string msg, object arg = null)
14+
{
15+
Console.ForegroundColor = ConsoleColor.Red;
16+
Console.WriteLine(msg, arg);
17+
Console.ResetColor();
18+
}
19+
public void Add(T entity)
20+
{
21+
Log("In Logger decorator - Before Adding {0}", entity);
22+
_decorated.Add(entity);
23+
Log("In Logger decorator - After Adding {0}", entity);
24+
}
25+
public void Delete(T entity)
26+
{
27+
Log("In Logger decorator - Before Deleting {0}", entity);
28+
_decorated.Delete(entity);
29+
Log("In Logger decorator - After Deleting {0}", entity);
30+
}
31+
32+
public T GetById(int id)
33+
{
34+
Log("In Logger decorator - Before Getting Entity {0}", id);
35+
var result = _decorated.GetById(id);
36+
Log("In Logger decorator - After Getting Entity {0}", id);
37+
return result;
38+
}
39+
}
40+
}

‎Decorator/TimerRepository.cs

+58
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Diagnostics;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading;
7+
using DecoratorProxyPattern.Repository;
8+
9+
namespace DecoratorProxyPattern.Decorator
10+
{
11+
public class TimerRepository<T> : IRepository<T>
12+
{
13+
private readonly IRepository<T> _decorated;
14+
private readonly Stopwatch _stopwatch;
15+
public TimerRepository(IRepository<T> decorated)
16+
{
17+
_decorated = decorated;
18+
_stopwatch = new Stopwatch();
19+
}
20+
private void Log(string msg, object arg = null)
21+
{
22+
Console.ForegroundColor = ConsoleColor.Red;
23+
Console.WriteLine(msg, arg);
24+
Console.ResetColor();
25+
}
26+
public void Add(T entity)
27+
{
28+
Log("In Timer decorator - Timer - Before Adding {0}", entity);
29+
_stopwatch.Start();
30+
Thread.Sleep(73);
31+
_decorated.Add(entity);
32+
_stopwatch.Stop();
33+
Log(string.Format("In Timer decorator - After Adding - {0} - Time {1}", entity, _stopwatch.ElapsedMilliseconds));
34+
_stopwatch.Reset();
35+
}
36+
public void Delete(T entity)
37+
{
38+
Log("In Timer decorator - Before Deleting {0}", entity);
39+
_stopwatch.Start();
40+
Thread.Sleep(43);
41+
_decorated.Delete(entity);
42+
Log(string.Format("In Timer decorator - After Adding - {0} - Time {1}", entity, _stopwatch.ElapsedMilliseconds));
43+
_stopwatch.Reset();
44+
45+
}
46+
47+
public T GetById(int id)
48+
{
49+
Log("In Timer decorator - Before Getting Entity {0}", id);
50+
_stopwatch.Start();
51+
Thread.Sleep(43);
52+
var result = _decorated.GetById(id);
53+
Log(string.Format("In Timer decorator - After Adding - {0} - Time {1}", id, _stopwatch.ElapsedMilliseconds));
54+
_stopwatch.Reset();
55+
return result;
56+
}
57+
}
58+
}

‎DecoratorProxyPattern.csproj

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{2923A08B-F08E-4498-B8F8-73599692F862}</ProjectGuid>
8+
<OutputType>Exe</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>DecoratorProxyPattern</RootNamespace>
11+
<AssemblyName>DecoratorProxyPattern</AssemblyName>
12+
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<PlatformTarget>AnyCPU</PlatformTarget>
17+
<DebugSymbols>true</DebugSymbols>
18+
<DebugType>full</DebugType>
19+
<Optimize>false</Optimize>
20+
<OutputPath>bin\Debug\</OutputPath>
21+
<DefineConstants>DEBUG;TRACE</DefineConstants>
22+
<ErrorReport>prompt</ErrorReport>
23+
<WarningLevel>4</WarningLevel>
24+
</PropertyGroup>
25+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
26+
<PlatformTarget>AnyCPU</PlatformTarget>
27+
<DebugType>pdbonly</DebugType>
28+
<Optimize>true</Optimize>
29+
<OutputPath>bin\Release\</OutputPath>
30+
<DefineConstants>TRACE</DefineConstants>
31+
<ErrorReport>prompt</ErrorReport>
32+
<WarningLevel>4</WarningLevel>
33+
</PropertyGroup>
34+
<ItemGroup>
35+
<Reference Include="System" />
36+
<Reference Include="System.Core" />
37+
<Reference Include="System.Xml.Linq" />
38+
<Reference Include="System.Data.DataSetExtensions" />
39+
<Reference Include="Microsoft.CSharp" />
40+
<Reference Include="System.Data" />
41+
<Reference Include="System.Xml" />
42+
</ItemGroup>
43+
<ItemGroup>
44+
<Compile Include="Proxy\TimerProxy.cs" />
45+
<Compile Include="Decorator\LoggerRepository.cs" />
46+
<Compile Include="Decorator\TimerRepository.cs" />
47+
<Compile Include="Model\Customer.cs" />
48+
<Compile Include="Proxy\DynamicProxy.cs" />
49+
<Compile Include="Repository\IRepository.cs" />
50+
<Compile Include="Program.cs" />
51+
<Compile Include="Properties\AssemblyInfo.cs" />
52+
<Compile Include="Repository\Repository.cs" />
53+
<Compile Include="Repository\RepositoryFactory.cs" />
54+
</ItemGroup>
55+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
56+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
57+
Other similar extension points exist, see Microsoft.Common.targets.
58+
<Target Name="BeforeBuild">
59+
</Target>
60+
<Target Name="AfterBuild">
61+
</Target>
62+
-->
63+
</Project>

‎Model/Customer.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace DecoratorProxyPattern.Model
2+
{
3+
public class Customer
4+
{
5+
public int Id { get; set; }
6+
public string Name { get; set; }
7+
public string Address { get; set; }
8+
}
9+
}

‎Program.cs

+101
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System;
2+
using DecoratorProxyPattern.Decorator;
3+
using DecoratorProxyPattern.Model;
4+
using DecoratorProxyPattern.Repository;
5+
6+
namespace DecoratorProxyPattern
7+
{
8+
/// <summary>
9+
/// Taken from
10+
/// http://msdn.microsoft.com/en-us/magazine/dn574804.aspx
11+
/// </summary>
12+
class Program
13+
{
14+
static void Main(string[] args)
15+
{
16+
NoDecoratorNoProxy();
17+
18+
OneDecoratorNoProxy();
19+
20+
TwoDecoratorsNoProxy();
21+
22+
NoDecoratorTwoProxies();
23+
}
24+
25+
26+
private static void NoDecoratorNoProxy()
27+
{
28+
Console.WriteLine("***\r\n Begin program - no logging\r\n");
29+
IRepository<Customer> customerRepository =
30+
new Repository<Customer>();
31+
var customer = new Customer
32+
{
33+
Id = 1,
34+
Name = "Customer 1",
35+
Address = "Address 1"
36+
};
37+
customerRepository.Add(customer);
38+
customerRepository.Delete(customer);
39+
Console.WriteLine("\r\nEnd program - no logging\r\n***");
40+
Console.ReadLine();
41+
}
42+
43+
private static void OneDecoratorNoProxy()
44+
{
45+
Console.WriteLine("***\r\n Begin program - logging with decorator\r\n");
46+
IRepository<Customer> customerRepository =
47+
new LoggerRepository<Customer>(new Repository<Customer>());
48+
var customer = new Customer
49+
{
50+
Id = 1,
51+
Name = "Customer 1",
52+
Address = "Address 1"
53+
};
54+
customerRepository.Add(customer);
55+
customerRepository.Delete(customer);
56+
Console.WriteLine("\r\nEnd program - logging with decorator\r\n***");
57+
Console.ReadLine();
58+
}
59+
60+
private static void TwoDecoratorsNoProxy()
61+
{
62+
Console.WriteLine("***\r\n Begin program - no logging\r\n");
63+
64+
var customerRepository =
65+
RepositoryFactory.CreateRepositoryWithDecorator<Customer>();
66+
var customer = new Customer
67+
{
68+
Id = 1,
69+
Name = "Customer 1",
70+
Address = "Address 1"
71+
};
72+
customerRepository.Add(customer);
73+
customerRepository.Delete(customer);
74+
Console.WriteLine("\r\nEnd program - no logging\r\n***");
75+
76+
Console.ReadLine();
77+
}
78+
79+
80+
81+
private static void NoDecoratorTwoProxies()
82+
{
83+
84+
Console.WriteLine("***\r\n Begin program - logging with dynamic proxy\r\n");
85+
86+
var customerRepository =
87+
RepositoryFactory.CreateRepositoryWithProxy<Customer>();
88+
var customer = new Customer
89+
{
90+
Id = 1,
91+
Name = "Customer 1",
92+
Address = "Address 1"
93+
};
94+
customerRepository.Add(customer);
95+
customerRepository.Delete(customer);
96+
Console.WriteLine("\r\nEnd program - logging with dynamic proxy\r\n***");
97+
Console.ReadLine();
98+
}
99+
100+
}
101+
}

‎Properties/AssemblyInfo.cs

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Reflection;
2+
using System.Runtime.CompilerServices;
3+
using System.Runtime.InteropServices;
4+
5+
// General Information about an assembly is controlled through the following
6+
// set of attributes. Change these attribute values to modify the information
7+
// associated with an assembly.
8+
[assembly: AssemblyTitle("DecoratorProxyPattern")]
9+
[assembly: AssemblyDescription("")]
10+
[assembly: AssemblyConfiguration("")]
11+
[assembly: AssemblyCompany("")]
12+
[assembly: AssemblyProduct("DecoratorProxyPattern")]
13+
[assembly: AssemblyCopyright("Copyright © 2014")]
14+
[assembly: AssemblyTrademark("")]
15+
[assembly: AssemblyCulture("")]
16+
17+
// Setting ComVisible to false makes the types in this assembly not visible
18+
// to COM components. If you need to access a type in this assembly from
19+
// COM, set the ComVisible attribute to true on that type.
20+
[assembly: ComVisible(false)]
21+
22+
// The following GUID is for the ID of the typelib if this project is exposed to COM
23+
[assembly: Guid("4c9fda3c-cfde-41d3-b869-f799c015d534")]
24+
25+
// Version information for an assembly consists of the following four values:
26+
//
27+
// Major Version
28+
// Minor Version
29+
// Build Number
30+
// Revision
31+
//
32+
// You can specify all the values or you can default the Build and Revision Numbers
33+
// by using the '*' as shown below:
34+
// [assembly: AssemblyVersion("1.0.*")]
35+
[assembly: AssemblyVersion("1.0.0.0")]
36+
[assembly: AssemblyFileVersion("1.0.0.0")]

‎Proxy/DynamicProxy.cs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.Remoting.Messaging;
4+
using System.Runtime.Remoting.Proxies;
5+
6+
namespace DecoratorProxyPattern.Proxy
7+
{
8+
class DynamicProxy<T> : RealProxy
9+
{
10+
private readonly T _decorated;
11+
public DynamicProxy(T decorated)
12+
: base(typeof(T))
13+
{
14+
_decorated = decorated;
15+
}
16+
private void Log(string msg, object arg = null)
17+
{
18+
Console.ForegroundColor = ConsoleColor.Red;
19+
Console.WriteLine(msg, arg);
20+
Console.ResetColor();
21+
}
22+
public override IMessage Invoke(IMessage msg)
23+
{
24+
var methodCall = msg as IMethodCallMessage;
25+
if (methodCall != null)
26+
{
27+
var methodInfo = methodCall.MethodBase as MethodInfo;
28+
Log("In Dynamic Proxy - Before executing '{0}'",
29+
methodCall.MethodName);
30+
try
31+
{
32+
if (methodInfo != null)
33+
{
34+
var result = methodInfo.Invoke(_decorated, methodCall.InArgs);
35+
Log("In Dynamic Proxy - After executing '{0}' ",
36+
methodCall.MethodName);
37+
return new ReturnMessage(result, null, 0,
38+
methodCall.LogicalCallContext, methodCall);
39+
}
40+
}
41+
catch (Exception e)
42+
{
43+
Log(string.Format(
44+
"In Dynamic Proxy- Exception {0} executing '{1}'", e),
45+
methodCall.MethodName);
46+
return new ReturnMessage(e, methodCall);
47+
}
48+
}
49+
throw new NotImplementedException();
50+
}
51+
}
52+
}

‎Proxy/TimerProxy.cs

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.Reflection;
4+
using System.Runtime.Remoting.Messaging;
5+
using System.Runtime.Remoting.Proxies;
6+
using System.Threading;
7+
8+
namespace DecoratorProxyPattern.Proxy
9+
{
10+
public class TimerProxy<T> : RealProxy
11+
{
12+
private readonly Stopwatch _stopwatch;
13+
14+
private readonly T _decorated;
15+
16+
public TimerProxy(T decorated)
17+
: base(typeof (T))
18+
{
19+
_decorated = decorated;
20+
_stopwatch = new Stopwatch();
21+
}
22+
23+
private void Log(string msg, object arg = null)
24+
{
25+
Console.ForegroundColor = ConsoleColor.Green;
26+
Console.WriteLine(msg, arg);
27+
Console.ResetColor();
28+
}
29+
30+
public override IMessage Invoke(IMessage msg)
31+
{
32+
var methodCall = msg as IMethodCallMessage;
33+
var methodInfo = methodCall.MethodBase as MethodInfo;
34+
35+
try
36+
{
37+
Log("In Timer Proxy - Start Taking Time",
38+
methodCall.MethodName);
39+
_stopwatch.Start();
40+
Thread.Sleep(33);
41+
var result = methodInfo.Invoke(_decorated, methodCall.InArgs);
42+
_stopwatch.Stop();
43+
Log(string.Format("In Timer Proxy - After Adding - {0} - Time {1}", methodCall.InArgs,
44+
_stopwatch.ElapsedMilliseconds));
45+
_stopwatch.Reset();
46+
47+
return new ReturnMessage(result, null, 0,
48+
methodCall.LogicalCallContext, methodCall);
49+
}
50+
catch (Exception e)
51+
{
52+
53+
return new ReturnMessage(e, methodCall);
54+
}
55+
}
56+
}
57+
}

‎Repository/IRepository.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace DecoratorProxyPattern.Repository
2+
{
3+
public interface IRepository<T>
4+
{
5+
void Add(T entity);
6+
void Delete(T entity);
7+
T GetById(int id);
8+
}
9+
}

‎Repository/Repository.cs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
3+
namespace DecoratorProxyPattern.Repository
4+
{
5+
public class Repository<T> : IRepository<T>
6+
{
7+
public void Add(T entity)
8+
{
9+
Console.WriteLine("Adding {0}", entity);
10+
}
11+
public void Delete(T entity)
12+
{
13+
Console.WriteLine("Deleting {0}", entity);
14+
}
15+
public T GetById(int id)
16+
{
17+
Console.WriteLine("Getting entity {0}", id);
18+
return default(T);
19+
}
20+
}
21+
}

‎Repository/RepositoryFactory.cs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using DecoratorProxyPattern.Decorator;
6+
using DecoratorProxyPattern.Proxy;
7+
8+
namespace DecoratorProxyPattern.Repository
9+
{
10+
/// <summary>
11+
/// we can’t call proxy directly, because DynamicProxy<T> isn’t an IRepository<Customer>
12+
/// </summary>
13+
public class RepositoryFactory
14+
{
15+
/// <summary>
16+
/// To use the decorated repository, you must use the GetTransparentProxy method, which will return an instance of IRepository<Customer>.
17+
/// Every method of this instance that’s called will go through the proxy’s Invoke method
18+
/// </summary>
19+
/// <typeparam name="T"></typeparam>
20+
/// <returns></returns>
21+
public static IRepository<T> CreateRepositoryWithProxy<T>()
22+
{
23+
var repository = new Repository<T>();
24+
25+
// var loggerRepository = new LoggerRepository<T>(repository);
26+
//var timingRepository = new TimerRepository<T>(loggerRepository);
27+
28+
var dynamicProxy = new DynamicProxy<IRepository<T>>(repository);
29+
var transparentProxy = dynamicProxy.GetTransparentProxy() as IRepository<T>;
30+
31+
var timingProxy = new TimerProxy<IRepository<T>>(transparentProxy);
32+
33+
return timingProxy.GetTransparentProxy() as IRepository<T>;
34+
}
35+
36+
public static IRepository<T> CreateRepositoryWithDecorator<T>()
37+
{
38+
var repository = new Repository<T>();
39+
40+
var loggerRepository = new LoggerRepository<T>(repository);
41+
var timingRepository = new TimerRepository<T>(loggerRepository);
42+
43+
return timingRepository;
44+
}
45+
46+
}
47+
}

0 commit comments

Comments
 (0)
Please sign in to comment.