如何删除 Castle 3.0 中 IContributeComponentModelConstruction 中的所有属性注入?

发布于 2025-01-04 12:12:35 字数 1089 浏览 1 评论 0原文

我今天遇到了一个有趣的问题。

以前,在 Castle 2.5.1 中,我们已经能够执行以下操作:

internal class PropertyInjectionContributor : IContributeComponentModelConstruction
{
    public void ProcessModel(IKernel kernel, ComponentModel model)
    {

        model.Properties
            .RemoveAll(ps => !ps.Property.HasCustomAttribute<InjectAttribute>() &&
                             !ps.Property.HasCustomAttribute<InjectOptionallyAttribute>());

(InjectAttribute 和 InjectOptionallyAttribute 是我们自己的应用程序框架域中的属性,该框架基于 Castle Windsor。)

我们这样做的原因删除是因为我们希望对注入或不注入哪些(公共)属性有更多的控制。

这是可能的,因为在 Castle 2.5.1 中,PropertySetCollection 是一个 Collection,它很乐意接受修改。 :-)(实际上,我注意到这是“原始”上游 Castle 2.5.1 还是我个人修改的版本,但尽管如此......)

在 Castle 3.0 中,PropertySetCollection 只是一个 IEnumerable,这意味着它不能修改的。现在,ComponentModel 有一个 *Add*Property() 方法,但没有 *Remove*Property() 方法,那么我现在到底该怎么做呢??? :-)

如有任何帮助,我们将不胜感激。我们不再将 Castle Windsor 以“源”格式嵌入到我们的项目中(这意味着我们可以根据需要进行小的修改...),而是使用纯 DLL(并将它们合并到我们的框架中)。这意味着所有暗示对 Castle 代码进行个人修补的“解决方案”都是无操作的。

TIA。

此致, 每

I ran into an interesting problem today.

Previously, with Castle 2.5.1, we've been able to do something like this:

internal class PropertyInjectionContributor : IContributeComponentModelConstruction
{
    public void ProcessModel(IKernel kernel, ComponentModel model)
    {

        model.Properties
            .RemoveAll(ps => !ps.Property.HasCustomAttribute<InjectAttribute>() &&
                             !ps.Property.HasCustomAttribute<InjectOptionallyAttribute>());

(InjectAttribute and InjectOptionallyAttribute are attributes in the domain of our own application framework, which is based on Castle Windsor.)

The reason why we're doing this removal is because we want to have more control over what (public) properties are being injected or not.

This was possible because in Castle 2.5.1, PropertySetCollection was a Collection, which would gladly accept modifications. :-) (actually, I'm note sure if this was the "pristine" upstream Castle 2.5.1 or my personally modified version, but nevertheless...)

With Castle 3.0, PropertySetCollection is just an IEnumerable which means that it cannot be modified. Now, the ComponentModel has an *Add*Property() method but no *Remove*Property() method, so how on earth do I get this done now??? :-)

Any help is appreciated. We're moving away from having Castle Windsor embedded in "source" format in our project (which meant that we could do small modifications as needed...), towards using the plain DLLs instead (and ILMerging them into our framework). This means that all "solutions" that imply personal patching of the Castle code is simply a no-op.

TIA.

Best regards,
Per

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

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

发布评论

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

评论(1

久夏青 2025-01-11 12:12:35

我在 http://docs.castleproject.org/ 找到了答案Windsor.Whats-New-In-Windsor-3.ashx,位于“属性依赖项过滤”类别下。这可能会起作用,只是还没有时间测试。

I found the answer at http://docs.castleproject.org/Windsor.Whats-New-In-Windsor-3.ashx, under the "Filtering of property dependencies" category. This will probably work, just haven't had time to test it yet.

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