Windsor 3.0 RC 1

13 views
Skip to first unread message

smolesen

unread,
Nov 25, 2011, 9:01:52 AM11/25/11
to Castle Project Users
Hi

In Windsor 2.5.3, the code below worked fine, however in Windsor 3.0
RC1 this throws the following exception:

Unable to cast object of type 'Castle.Proxies.IMyServiceProxy' to type
'IService'.

Is this a change in 3.0 ??

TIA

Søren


public class MyInterceptor : IInterceptor
{
public void Intercept(IInvocation invocation)
{
invocation.Proceed();
}
}

public class InterceptorSelector : IModelInterceptorsSelector
{
public bool HasInterceptors(ComponentModel model)
{
return
typeof(IMyService).IsAssignableFrom(model.Implementation);
}

public InterceptorReference[]
SelectInterceptors(ComponentModel model, InterceptorReference[]
interceptors)
{
if
(typeof(IMyService).IsAssignableFrom(model.Implementation))
{
var tmp = new List<InterceptorReference>
{ InterceptorReference.ForType<MyInterceptor>() };
return tmp.ToArray();
}
return interceptors;
}
}

public interface IService
{

}
public interface IMyService
{
string Helloworld();
}

public abstract class ServiceBase : IService
{

}

public class MyServiceClass : ServiceBase, IMyService
{
public string Helloworld()
{
return "Hello world";
}
}

class Program
{
static void Main(string[] args)
{
var container = new WindsorContainer();
container.Kernel.ProxyFactory.AddInterceptorSelector(new
InterceptorSelector());
container.Register(Component.For<MyInterceptor>());

container.Register(Component.For<IMyService>().ImplementedBy<MyServiceClass>().Named("testService"));
var sut = container.Resolve<IService>("testService");

var res = ((IMyService)sut).Helloworld();
}
}

Krzysztof Koźmic

unread,
Nov 25, 2011, 6:44:21 PM11/25/11
to castle-pro...@googlegroups.com
This is a known and documented breaking change.

from breakingchanges.txt

change - Proxies no longer implicitly implement all interfaces of
component implementation type.

impact - medium
fixability - medium

description - This original behavior was actually a bug and would
produce unpredictible behavior
for components exposing several services including their class.

fix - if you were depending on the additional non-service intrfaces
being forwarded to the proxy
specify them explicitly as addtional interfaces to proxy:
container.Register(Component.For<CountingInterceptor>()
.Named("a"),
Component.For<ICommon>()
.ImplementedBy<TwoInterfacesImpl>()
.Interceptors("a")
.Proxy.AdditionalInterfaces(typeof(ICommon2))
.LifeStyle.Transient);


cheers,
Krzysztof

Søren M. Olesen

unread,
Nov 26, 2011, 9:34:52 AM11/26/11
to Castle Project Users

Yeah, I can see what you mean... Normally I wouldn't be able to cast
an instance of MyServiceClass to IService, so it makes goos sense that
I can't using Windsor either...

Thanks....

Søren


On Nov 26, 12:44 am, Krzysztof Koźmic <krzysztof.koz...@gmail.com>
wrote:

Reply all
Reply to author
Forward
0 new messages