Permalink
Browse files

Break Castle.Core dependency from Rhino.ServiceBus and add support fo…

…r Spring proxy detection
  • Loading branch information...
lahma authored and CoreyKaylor committed Jan 15, 2012
1 parent a316fe5 commit c4a3d4352ff9ccb919e521981e98739823965076
@@ -78,7 +78,7 @@ public void RegisterDefaultServices()
container.Register(
Component.For<IReflection>()
.LifeStyle.Is(LifestyleType.Singleton)
- .ImplementedBy<DefaultReflection>(),
+ .ImplementedBy<CastleReflection>(),
Component.For<IMessageSerializer>()
.LifeStyle.Is(LifestyleType.Singleton)
@@ -1,14 +1,15 @@
-using System;
+using System;
using System.Runtime.Remoting;
using Castle.DynamicProxy;
+using Rhino.ServiceBus.Impl;
-namespace Rhino.ServiceBus.Util
+namespace Rhino.ServiceBus.Castle
{
- //Pulled from Castle.Windsor
- public static class ProxyUtil
+ public class CastleReflection : DefaultReflection
{
- public static Type GetUnproxiedType(object instance)
+ public override Type GetUnproxiedType(object instance)
{
+ //Pulled from Castle.Windsor
if (!RemotingServices.IsTransparentProxy(instance))
{
IProxyTargetAccessor accessor = instance as IProxyTargetAccessor;
@@ -27,8 +28,5 @@ public static Type GetUnproxiedType(object instance)
}
return instance.GetType();
}
-
-
-
}
}
@@ -62,6 +62,7 @@
<ItemGroup>
<Compile Include="CastleBootStrapper.cs" />
<Compile Include="CastleBuilder.cs" />
+ <Compile Include="CastleReflection.cs" />
<Compile Include="CastleServiceLocator.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="CastleLoadBalancerBootStrapper.cs" />
@@ -47,6 +47,9 @@
<HintPath>$(LibDir)Rhino.Queues.dll</HintPath>
<SpecificVersion>False</SpecificVersion>
</Reference>
+ <Reference Include="Spring.Aop">
+ <HintPath>$(LibDir)Spring.Aop.dll</HintPath>
+ </Reference>
<Reference Include="Spring.Core">
<HintPath>$(LibDir)Spring.Core.dll</HintPath>
</Reference>
@@ -65,6 +68,7 @@
<Compile Include="SpringBootStrapper.cs" />
<Compile Include="SpringBuilder.cs" />
<Compile Include="SpringLoadBalancerBootStrapper.cs" />
+ <Compile Include="SpringReflection.cs" />
<Compile Include="SpringServiceLocator.cs" />
<Compile Include="Extensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -56,7 +56,7 @@ public void RegisterDefaultServices()
}
- applicationContext.RegisterSingleton<IReflection>(() => new DefaultReflection());
+ applicationContext.RegisterSingleton<IReflection>(() => new SpringReflection());
applicationContext.RegisterSingleton(config.SerializerType);
applicationContext.RegisterSingleton<IEndpointRouter>(() => new EndpointRouter());
}
@@ -0,0 +1,19 @@
+using System;
+using System.Runtime.Remoting;
+using Rhino.ServiceBus.Impl;
+using Spring.Aop.Framework;
+
+namespace Rhino.ServiceBus.Spring
+{
+ public class SpringReflection : DefaultReflection
+ {
+ public override Type GetUnproxiedType(object instance)
+ {
+ if (!RemotingServices.IsTransparentProxy(instance))
+ {
+ return AopUtils.GetTargetType(instance);
+ }
+ return instance.GetType();
+ }
+ }
+}
@@ -6,7 +6,6 @@
using System.Xml.Linq;
using log4net;
using Rhino.ServiceBus.Internal;
-using Rhino.ServiceBus.Util;
namespace Rhino.ServiceBus.Impl
{
@@ -179,7 +178,7 @@ public object Get(object instance, string name)
public Type GetGenericTypeOf(Type type, object msg)
{
- return GetGenericTypeOf(type, ProxyUtil.GetUnproxiedType(msg));
+ return GetGenericTypeOf(type, GetUnproxiedType(msg));
}
public Type GetGenericTypeOf(Type type, Type paramType)
@@ -194,7 +193,7 @@ public Type GetGenericTypeOf(Type type, params Type[] paramTypes)
public ICollection<Type> GetGenericTypesOfWithBaseTypes(Type type, object msg)
{
- return GetGenericTypesOfWithBaseTypes(type, ProxyUtil.GetUnproxiedType(msg));
+ return GetGenericTypesOfWithBaseTypes(type, GetUnproxiedType(msg));
}
public ICollection<Type> GetGenericTypesOfWithBaseTypes(Type type, Type paramType)
@@ -417,6 +416,12 @@ public Type[] GetMessagesConsumed(Type consumerType, Predicate<Type> filter)
return list.ToArray();
}
+ public virtual Type GetUnproxiedType(object instance)
+ {
+ // default to not understanding proxies
+ return instance.GetType();
+ }
+
#endregion
}
}
@@ -9,7 +9,6 @@
using Rhino.ServiceBus.MessageModules;
using Rhino.ServiceBus.Messages;
using Rhino.ServiceBus.Sagas;
-using Rhino.ServiceBus.Util;
namespace Rhino.ServiceBus.Impl
{
@@ -521,7 +520,7 @@ private object[] GetSagasFor(object message)
Type sagaType = sagaHandler.Implementation;
//first try to execute any saga finders.
- Type sagaFinderType = reflection.GetGenericTypeOf(typeof(ISagaFinder<,>), sagaType, ProxyUtil.GetUnproxiedType(message));
+ Type sagaFinderType = reflection.GetGenericTypeOf(typeof(ISagaFinder<,>), sagaType, reflection.GetUnproxiedType(message));
var sagaFinderHandlers = serviceLocator.GetAllHandlersFor(sagaFinderType);
foreach (var sagaFinderHandler in sagaFinderHandlers)
{
@@ -51,6 +51,9 @@ public interface IReflection
object InvokeFromElement(object covertor, XElement value);
XElement InvokeToElement(object covertor, object value, Func<Type, XNamespace> getNamespace);
+
string GetNameForXml(Type type);
+
+ Type GetUnproxiedType(object instance);
}
}
@@ -42,9 +42,6 @@
<LibDir>..\SharedLibs\4.0\</LibDir>
</PropertyGroup>
<ItemGroup>
- <Reference Include="Castle.Core">
- <HintPath>$(LibDir)Castle.Core.dll</HintPath>
- </Reference>
<Reference Include="Esent.Interop">
<HintPath>..\SharedLibs\Esent.Interop.dll</HintPath>
</Reference>
@@ -246,7 +243,6 @@
<Compile Include="RhinoQueues\TimeoutAction.cs" />
<Compile Include="Transport\TransportUtil.cs" />
<Compile Include="Util\CurrentMessage.cs" />
- <Compile Include="Util\ProxyUtil.cs" />
<Compile Include="Util\SerializationExtensions.cs" />
<Compile Include="Util\UriExtensions.cs" />
<None Include="PublicApi.cd" />
@@ -36,9 +36,11 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Castle.Core">
+ <SpecificVersion>False</SpecificVersion>
<HintPath>$(LibDir)Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Castle.Windsor">
+ <SpecificVersion>False</SpecificVersion>
<HintPath>$(LibDir)Castle.Windsor.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821, processorArchitecture=MSIL">
Binary file not shown.
Binary file not shown.
Oops, something went wrong.

0 comments on commit c4a3d43

Please sign in to comment.