Skip to content

Commit 8067a58

Browse files
author
Elad Zelingher
committed
Replacing new ProxyGenerator() with a static instance
1 parent d57d93f commit 8067a58

File tree

11 files changed

+55
-6
lines changed

11 files changed

+55
-6
lines changed

src/mono/WampSharp/WampSharp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@
248248
<Compile Include="..\..\net45\WampSharp\Core\Utilities\AsyncDisposable\AsyncDisposableExtensions.cs">
249249
<Link>Core\Utilities\AsyncDisposable\AsyncDisposableExtensions.cs</Link>
250250
</Compile>
251+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\CastleDynamicProxyGenerator.cs">
252+
<Link>Core\Utilities\CastleDynamicProxyGenerator.cs</Link>
253+
</Compile>
251254
<Compile Include="..\..\net45\WampSharp\Core\Utilities\CustomAttributeExtensions.cs">
252255
<Link>Core\Utilities\CustomAttributeExtensions.cs</Link>
253256
</Compile>

src/net40/WampSharp/WampSharp.csproj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@
251251
<Compile Include="..\..\net45\WampSharp\Core\Utilities\AsyncDisposable\AsyncDisposableExtensions.cs">
252252
<Link>Core\Utilities\AsyncDisposable\AsyncDisposableExtensions.cs</Link>
253253
</Compile>
254+
<Compile Include="..\..\net45\WampSharp\Core\Utilities\CastleDynamicProxyGenerator.cs">
255+
<Link>Core\Utilities\CastleDynamicProxyGenerator.cs</Link>
256+
</Compile>
254257
<Compile Include="..\..\net45\WampSharp\Core\Utilities\CustomAttributeExtensions.cs">
255258
<Link>Core\Utilities\CustomAttributeExtensions.cs</Link>
256259
</Compile>

src/net45/WampSharp.WAMP1/WAMP1/V1/Core/Listener/ClientBuilder/WampClientBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using WampSharp.Core.Listener;
33
using WampSharp.Core.Message;
44
using WampSharp.Core.Proxy;
5+
using WampSharp.Core.Utilities;
56
using WampSharp.V1.Core.Contracts;
67
using WampSharp.V1.Core.Curie;
78
using WampSharp.V1.Core.Proxy;
@@ -18,7 +19,7 @@ public class WampClientBuilder<TMessage> : IWampClientBuilder<TMessage, IWampCli
1819
#region Members
1920

2021
private readonly IWampClientContainer<TMessage, IWampClient> mContainer;
21-
private readonly ProxyGenerator mGenerator = new ProxyGenerator();
22+
private readonly ProxyGenerator mGenerator = CastleDynamicProxyGenerator.Instance;
2223
private readonly IWampOutgoingRequestSerializer mOutgoingSerializer;
2324
private readonly IWampOutgoingMessageHandlerBuilder<TMessage> mOutgoingHandlerBuilder;
2425

src/net45/WampSharp.WAMP1/WAMP1/V1/Rpc/Client/WampRpcClientFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Castle.DynamicProxy;
22
using WampSharp.Core.Listener;
3+
using WampSharp.Core.Utilities;
34

45
namespace WampSharp.V1.Rpc.Client
56
{
@@ -10,7 +11,7 @@ namespace WampSharp.V1.Rpc.Client
1011
/// <typeparam name="TMessage"></typeparam>
1112
public class WampRpcClientFactory<TMessage> : IWampRpcClientFactory<TMessage>
1213
{
13-
private readonly ProxyGenerator mProxyGenerator = new ProxyGenerator();
14+
private readonly ProxyGenerator mProxyGenerator = CastleDynamicProxyGenerator.Instance;
1415
private readonly IWampRpcSerializer mSerializer;
1516
private readonly IWampRpcClientHandlerBuilder<TMessage> mClientHandlerBuilder;
1617

src/net45/WampSharp/Core/Client/WampServerProxyBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using WampSharp.Core.Listener;
44
using WampSharp.Core.Message;
55
using WampSharp.Core.Proxy;
6+
using WampSharp.Core.Utilities;
67

78
namespace WampSharp.Core.Client
89
{
@@ -16,7 +17,7 @@ public class WampServerProxyBuilder<TMessage, TRawClient, TServer> : IWampServer
1617
where TServer : class
1718
{
1819
private readonly IWampServerProxyOutgoingMessageHandlerBuilder<TMessage, TRawClient> mOutgoingHandlerBuilder;
19-
private readonly ProxyGenerator mProxyGenerator = new ProxyGenerator();
20+
private readonly ProxyGenerator mProxyGenerator = CastleDynamicProxyGenerator.Instance;
2021
private readonly IWampOutgoingRequestSerializer mOutgoingSerializer;
2122

2223
/// <summary>

src/net45/WampSharp/Core/Serialization/WampMessageSerializerFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#if CASTLE
22
using Castle.DynamicProxy;
33
using WampSharp.Core.Proxy;
4+
using WampSharp.Core.Utilities;
45

56
namespace WampSharp.Core.Serialization
67
{
@@ -11,7 +12,7 @@ namespace WampSharp.Core.Serialization
1112
/// <typeparam name="TMessage"></typeparam>
1213
public class WampMessageSerializerFactory<TMessage> : IWampMessageSerializerFactory
1314
{
14-
private readonly ProxyGenerator mGenerator = new ProxyGenerator();
15+
private readonly ProxyGenerator mGenerator = CastleDynamicProxyGenerator.Instance;
1516
private readonly WampSerializationInterceptor<TMessage> mSerializationInterceptor;
1617

1718
/// <summary>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#if CASTLE
2+
3+
using System;
4+
using System.Threading;
5+
using Castle.DynamicProxy;
6+
7+
namespace WampSharp.Core.Utilities
8+
{
9+
internal static class CastleDynamicProxyGenerator
10+
{
11+
private static string PREFIX = typeof(CastleDynamicProxyGenerator).Assembly.GetName().Name + ".";
12+
13+
public static readonly ProxyGenerator Instance = GetProxyGenerator();
14+
15+
private static ProxyGenerator GetProxyGenerator()
16+
{
17+
ModuleScope moduleScope = GetModuleScope();
18+
return new ProxyGenerator(new DefaultProxyBuilder(moduleScope));
19+
}
20+
21+
private static ModuleScope GetModuleScope()
22+
{
23+
return new ModuleScope(savePhysicalAssembly: false,
24+
disableSignedModule: false,
25+
strongAssemblyName: PREFIX + ModuleScope.DEFAULT_ASSEMBLY_NAME,
26+
strongModulePath: PREFIX + ModuleScope.DEFAULT_FILE_NAME,
27+
weakAssemblyName: PREFIX + ModuleScope.DEFAULT_ASSEMBLY_NAME,
28+
weakModulePath: PREFIX + ModuleScope.DEFAULT_FILE_NAME);
29+
}
30+
}
31+
}
32+
33+
#endif

src/net45/WampSharp/WAMP2/V2/Api/CalleeProxy/WampCalleeProxyFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22
using System.Linq;
33
using System.Reflection;
44
using Castle.DynamicProxy;
5+
using WampSharp.Core.Utilities;
56

67
namespace WampSharp.V2.CalleeProxy
78
{
89
internal class WampCalleeProxyFactory : IWampCalleeProxyFactory
910
{
10-
private readonly ProxyGenerator mGenerator = new ProxyGenerator();
11+
private readonly ProxyGenerator mGenerator = CastleDynamicProxyGenerator.Instance;
1112
private readonly WampCalleeProxyInvocationHandler mHandler;
1213

1314
public WampCalleeProxyFactory(WampCalleeProxyInvocationHandler handler)

src/net45/WampSharp/WAMP2/V2/Core/Listener/ClientBuilder/WampClientBuilder.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using WampSharp.Core.Listener;
44
using WampSharp.Core.Message;
55
using WampSharp.Core.Proxy;
6+
using WampSharp.Core.Utilities;
67
using WampSharp.V2.Authentication;
78
using WampSharp.V2.Binding;
89
using WampSharp.V2.Core.Contracts;
@@ -21,7 +22,7 @@ public class WampClientBuilder<TMessage> : IWampClientBuilder<TMessage, IWampCli
2122
#region Members
2223

2324
private readonly IWampClientContainer<TMessage, IWampClientProxy<TMessage>> mContainer;
24-
private readonly ProxyGenerator mGenerator = new ProxyGenerator();
25+
private readonly ProxyGenerator mGenerator = CastleDynamicProxyGenerator.Instance;
2526
private readonly IWampOutgoingRequestSerializer mOutgoingSerializer;
2627
private readonly IWampOutgoingMessageHandlerBuilder<TMessage> mOutgoingHandlerBuilder;
2728
private readonly IWampIdGenerator mSessionIdGenerator;

src/net45/WampSharp/WampSharp.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@
133133
<Compile Include="Core\Serialization\WampMessageSerializerFactory.cs" />
134134
<Compile Include="Core\Serialization\WampSerializationInterceptor.cs" />
135135
<Compile Include="Core\Utilities\AsyncDisposable\AsyncDisposableExtensions.cs" />
136+
<Compile Include="Core\Utilities\CastleDynamicProxyGenerator.cs" />
136137
<Compile Include="Core\Utilities\CustomAttributeExtensions.cs" />
137138
<Compile Include="Core\Utilities\DictionaryExtensions.cs" />
138139
<Compile Include="Core\Utilities\GenericTypeExtensions.cs" />

0 commit comments

Comments
 (0)