1
votes

I'm having a strange issue trying to upgrade from Nancy 0.7 to 0.12. Previously I was registering a facility to do logging for all my services inside my bootstrapper:

    protected override void ConfigureApplicationContainer(IWindsorContainer existingContainer)
    {
        existingContainer.AddFacility<LoggingFacility>();
        existingContainer.Register(Component.For<LoggingInterceptor>());
        ...other registration
    }

LoggingFacility looks like this:

public class LoggingFacility : AbstractFacility 
{
    protected override void Init() { Kernel.ComponentRegistered += KernelComponentRegistered; }

    static void KernelComponentRegistered(string key, IHandler handler)
    {
        if (!ShouldProxyComponent(handler))
            return;

        // Don't add more than one logging interceptor to a component
        handler.ComponentModel.Interceptors.AddIfNotInCollection(InterceptorReference.ForType<LoggingInterceptor>());
    }

    static bool ShouldProxyComponent(IHandler handler)
    {
        //Don't log interceptors themselves
        if (typeof(IInterceptor).IsAssignableFrom(handler.ComponentModel.Implementation)) 
            return false;

        //Don't put proxy around any late-bound (usually factory-created) component
        if (handler.ComponentModel.Implementation == typeof(LateBoundComponent))
            return false;

        return true;
    }
}

Unfortunately since upgrading to 0.12/Castle 3.1, the following line in WindsorNancyBootstrapper.RegisterTypes is causing some problems

        container.Register(Component.For<Func<IRouteCache>>()
            .UsingFactoryMethod(ctx => (Func<IRouteCache>) (ctx.Resolve<IRouteCache>)));

Basically, Castle tries to create a dynamic proxy around Func. This would be fine if this registration triggered the event my facility subscribed to, to but it doesn't. And yet the interceptor seems to be registered anyway.

When trying to create a proxy it obviously fails because MulticastDelgate (IL's parent for Func<>) is sealed: TypeLoadException Could not load type 'Castle.Proxies.Func`1Proxy' from assembly 'DynamicProxyGenAssembly2, Version=0.0.0.0, Culture=neutral, PublicKeyToken=a621a9e7e5c32e69' because the parent type is sealed.

I'm not sure what do here, does anyone have any experience with Facilities and Nancy 0.12?

1

1 Answers

1
votes

The solution for me turned out to be to register the Castle TypedFactoryFacility as part of my override of the Nancy bootstrapper:

existingContainer.AddFacility<TypedFactoryFacility>();

There is a pull request into Nancy.Bootstrappers.Windsor that includes that change as part of the rest of the changes