结构图 202 - 为什么?

发布于 2024-08-19 16:01:28 字数 888 浏览 2 评论 0原文

好的,我正在尝试为我向 SM 注册的类型设置属性。

这是我的一个组件中的注册表中的代码。这 在控制台应用程序的配置过程中添加注册表。 当我尝试访问实例的 EndorsementSpecs 属性时 AutoMandatoryEndorsementAggregator 对象,我得到 202。什么是 有趣的是我可以打电话 GetAllInstances>() 来自我的 控制台应用程序,它解决得很好。有什么关于 从 OnCreation 中访问此代码会导致 202?我 可以在 WhatDoIHave() 中看到我期望的一切。我也尝试过 TypeInterceptor ,得到了相同的结果。

//register all open generics
cfg.ConnectImplementationsToTypesClosing(typeof
(MandatoryEndorsementSpecBase<>));

ForSingletonOf<IMandatoryEndorsementAggregator<AutoPolicy>>()
                    .Use<AutoMandatoryEndorsementAggregator>()
                    .OnCreation((context, x) =>
                    {

                        var specs =
context.GetAllInstances<MandatoryEndorsementSpecBase<AutoPolicy>>();
                        x.EndorsementSpecs = specs;
                    })
                    ; 

OK, I'm trying to set a property on a type I'm registering with SM.

Here's the code from the registry in one of my components. This
registry is being added during the configuration from a console app.
When I try to access the EndorsementSpecs property of the instance
AutoMandatoryEndorsementAggregator object, I get the 202. What's
interesting is that I can call
GetAllInstances>() from my
console app and it resolves just fine. Is there something about
accessing this code from within OnCreation that is causing the 202? I
can see everything I expect in WhatDoIHave(). I've also tried a TypeInterceptor with the same results.

//register all open generics
cfg.ConnectImplementationsToTypesClosing(typeof
(MandatoryEndorsementSpecBase<>));

ForSingletonOf<IMandatoryEndorsementAggregator<AutoPolicy>>()
                    .Use<AutoMandatoryEndorsementAggregator>()
                    .OnCreation((context, x) =>
                    {

                        var specs =
context.GetAllInstances<MandatoryEndorsementSpecBase<AutoPolicy>>();
                        x.EndorsementSpecs = specs;
                    })
                    ; 

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

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

发布评论

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

评论(1

悍妇囚夫 2024-08-26 16:01:28

很抱歉转移您的真正问题,但是您是否只是想将 MandatoryEndorsementSpecBase 的所有实例注入 AutoMandatoryEndorsementAggregatory 中?
如果是这样,您可能只需将其设置为构造函数参数即可,以便它们全部自动注入。

public AutoMandatoryEndorsementAggregatory(MandatoryEndorsementSpecBase<AutoPolicy>[] endorsementSpecs){
  EndorsementSpecs = endorsementSpecs;
}

Sorry to deflect your real questions, but are you just trying to inject all instances of MandatoryEndorsementSpecBase into AutoMandatoryEndorsementAggregatory?
If so, you can probably get away with just making it a constructor parameter so that they are all automatically injected.

public AutoMandatoryEndorsementAggregatory(MandatoryEndorsementSpecBase<AutoPolicy>[] endorsementSpecs){
  EndorsementSpecs = endorsementSpecs;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文