温莎城堡:如何以编程方式注册列表(而不是使用配置文件)

发布于 2024-09-25 20:15:57 字数 379 浏览 1 评论 0原文

我想使用列表参数注册一个对象,但不使用配置文件。 这是我当前使用的配置文件:

<?xml version="1.0" encoding="utf-8" ?>
<castle>
  <components>
    <component id="EmailParser"
     service="ESImportCommon.Email.IEmailParser, ESImportCommon"
     type="ESImportCommon.Email.EmailParser, ESImportCommon">
    </component>
  </components>
</castle>

I would like to register an object with a list parameter, but without using a configuration file.
this is the configuration file that I currently use:

<?xml version="1.0" encoding="utf-8" ?>
<castle>
  <components>
    <component id="EmailParser"
     service="ESImportCommon.Email.IEmailParser, ESImportCommon"
     type="ESImportCommon.Email.EmailParser, ESImportCommon">
    </component>
  </components>
</castle>

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

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

发布评论

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

评论(1

世界如花海般美丽 2024-10-02 20:15:57

您可以这样做:

        using ESImportCommon.Email;

        ....

        var container = new WindsorContainer(new XmlInterpreter()); 
        container.AddFacility<FactorySupportFacility>();
        container.Register(Component.For<IEmailParser>().ImplementedBy<EmailParser>());

请注意,如果您不想在 Web/应用程序中进行任何配置,则无需将 XmlInterpreter 实例传递给构造函数。配置。

You can do it like this:

        using ESImportCommon.Email;

        ....

        var container = new WindsorContainer(new XmlInterpreter()); 
        container.AddFacility<FactorySupportFacility>();
        container.Register(Component.For<IEmailParser>().ImplementedBy<EmailParser>());

Note that you don't need to pass an instance of XmlInterpreter to the constructor if you do not want any configuration in your web/app.config.

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