粘土和温莎城堡 2.5

发布于 2024-09-17 20:57:21 字数 2199 浏览 5 评论 0原文

我刚刚下载了动态对象框架 Clay 并遇到了有关 castle 项目 版本。 Clay 使用“castle”v2.0 的功能,而我有一个项目已经开始引用 v2.5。不用说,只是为了让事情变得更有趣,我在所有“城堡”和 IoC 方面都是一个完全的初学者。

真正的问题是升级clay 解决方案中的引用会导致折旧方法警告。无论您是否抑制该方法,所提供的单元测试都会失败,并在“InterfaceProxyBehavior”的“Intercept”中的以下代码中出现“无法对空引用执行运行时绑定”异常:

       var invoker = BindInvoker(invocation);
       invoker(invocation);

产生运行时警告的代码位于“DefaultClayActivator”的“CreateInstance”中:

       //var proxyType = _builder.CreateClassProxy(baseType, options);
       var proxyType = _builder.CreateClassProxyType(baseType, null, options);

如前所述,我仍然是温莎城堡的初学者,刚刚开始使用 IoC,所以还没有遇到过代理的东西。令人沮丧的是,我不知道错误消息告诉我什么或要求什么。

是否有人已经将 Clay 移植到了 castle 项目的 2.5 版本,因此请了解所需的步骤。或者任何对城堡这一部分有经验的人都可以进一步阐明该错误以及我可能需要采取哪些措施来解决它。

已更新

我仍然对失败的功能一无所知,但有机会重新审视使​​用 v2.0(有效)和 v2.5(中断)运行它的代码在 castle.core 中。附件是调试信息的两张图片,分别是工作时和崩溃时的信息。它失败的测试如下,我已用评论指出了该调用。

namespace ClaySharp.Tests {
    [TestFixture]
    public class BinderFallbackTests {
       ...
    [Test]
    public void TestInvokePaths() {
        var dynamically = ClayActivator.CreateInstance<Alpha>(new IClayBehavior[] { 
            new InterfaceProxyBehavior(), 
            new AlphaBehavior() 
        });
        Alpha statically = dynamically;
        IAlpha interfacially = dynamically;

        Assert.That(dynamically.Hello(), Is.EqualTo("World-"));
        Assert.That(statically.Hello(), Is.EqualTo("World-"));
        Assert.That(interfacially.Hello(), Is.EqualTo("World-"));  // <- Fails on this call

        Assert.That(dynamically.Foo(), Is.EqualTo("Bar-"));
        Assert.That(interfacially.Foo(), Is.EqualTo("Bar-"));

        Assert.Throws<RuntimeBinderException>(() => dynamically.MissingNotHandled());
    }
    ...
  }
}

这是使用castle.core v2.5时的调试信息,抛出异常: alt text

这是使用 castle.core v2.0(有效)针对同一调用/线路的调试信息导致 v2.5 出现问题 替代文本

I've just downloaded the dynamic object framework Clay and am running into issues regarding castle project versions. Clay uses functionality from v2.0 of "castle" whilst I have a project which has been started referencing v2.5. Needless to say just to make matters more interesting I'm a complete beginner in all things "Castle" and IoC.

The real problem is that upgrading the references within clay solution results in a depreciated method warning. Regardless of whether you supress the method or not, the provided unit tests fail with a "Cannot perform runtime binding on a null reference" exception in the following code in "Intercept" of "InterfaceProxyBehavior":

       var invoker = BindInvoker(invocation);
       invoker(invocation);

The code that produces the run-time warning is in "CreateInstance" of "DefaultClayActivator":

       //var proxyType = _builder.CreateClassProxy(baseType, options);
       var proxyType = _builder.CreateClassProxyType(baseType, null, options);

As previously stated I'm still a complete beginner with Castle Windsor and just starting out with IoC so haven't even come across the Proxy stuff yet. Frustratingly I have no idea what the error message is even telling me, or asking for.

Have anyone already ported Clay across to version 2.5 of the castle project, so know the steps needed. Or can any one with experience of this part of castle throw anymore light on the error and what I may need to do to resolve it.

Updated

I'm still not really any the wiser as to the functionality that is failing, but have had chance to revisit the code running it both with v2.0 (works) and v2.5 (breaks) in castle.core. Attached are two images of the debug information when it works and then when it breaks. The test that it fails on is below, I've indicated the call with a comment.

namespace ClaySharp.Tests {
    [TestFixture]
    public class BinderFallbackTests {
       ...
    [Test]
    public void TestInvokePaths() {
        var dynamically = ClayActivator.CreateInstance<Alpha>(new IClayBehavior[] { 
            new InterfaceProxyBehavior(), 
            new AlphaBehavior() 
        });
        Alpha statically = dynamically;
        IAlpha interfacially = dynamically;

        Assert.That(dynamically.Hello(), Is.EqualTo("World-"));
        Assert.That(statically.Hello(), Is.EqualTo("World-"));
        Assert.That(interfacially.Hello(), Is.EqualTo("World-"));  // <- Fails on this call

        Assert.That(dynamically.Foo(), Is.EqualTo("Bar-"));
        Assert.That(interfacially.Foo(), Is.EqualTo("Bar-"));

        Assert.Throws<RuntimeBinderException>(() => dynamically.MissingNotHandled());
    }
    ...
  }
}

This is the debug information when using v2.5 of castle.core and the exception is thrown:
alt text

This is the debug information using v2.0 of castle.core (which works) for the same call / line that causes the problem with v2.5
alt text

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

允世 2024-09-24 20:57:21

看来我解决了这个问题。 (所有测试都通过)

请参阅我创建的 codeplex 上的工作项以及我推送到分支的更改:
http://clay.codeplex.com/SourceControl/network/Forks/remcoros/Clay

It seems I fixed this. (all tests passing)

See the workitem on codeplex I created and the changes I pushed to my fork:
http://clay.codeplex.com/SourceControl/network/Forks/remcoros/Clay

沉默的熊 2024-09-24 20:57:21

我从来没有使用过这个粘土东西,所以下面的所有内容都是基于假设。

来自 BindInvoker 的错误消息不是 Castle 错误,但我猜测它的发生是因为调用者试图绑定到代理的调用目标,在某些情况下,该代理在 DynamicProxy 2.1 中曾经有一个值,这是错误的,后来的版本 2.2 和 2.5 修复了这个问题,但这是您现在正在经历的一个重大更改。

另一条错误消息告诉你

使用CreateClassProxyType方法
相反。

这是您注释掉的另一种方法。这里有什么不明显的?

I have never used this Clay thing, so all stuff below is based on assumptions.

The error message from BindInvoker is not a Castle error, but I'm guessing it's happening because the invoker is trying to bind to invocation target of the proxy which in DynamicProxy 2.1 used to have a value in some cases, which was wrong, and later versions 2.2 and 2.5 fixed that but it was a breaking change that you're now experiencing.

The other error message is telling you

Use CreateClassProxyType method
instead.

Which is the other method you commented out. What's not obvious here?

゛时过境迁 2024-09-24 20:57:21

关于 Clay 动态对象的一些不错的教程:

  • 可延展的 C# 动态对象第 1 部分 链接

  • 可延展的 C# 动态对象第 2 部分 链接

Some nice tutorials on Clay dynamic objects:

  • Malleable C# dynamic objects Part 1 Link

  • Malleable C# dynamic objects Part 2 Link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文