首页 > 解决方案 > 在 .NET 的嵌套配置部分中指定类类型

问题描述

我一直在浏览我可以找到的所有关于 ConfigurationSection 和 ConfigurationElement 的文档,试图弄清楚如何嵌套而不用大量的 XML 解析来污染我的类——而且似乎找不到任何东西。

需要进行一些额外的重构,以便我可以注入更多的依赖项 - 但这应该足以让您了解我正在尝试做的事情,并可能为我指明正确的方向:

Dim mediInfo = New MeditechInfo
    With mediInfo
        .ADMDb = My.Settings.MeditechADM
        .Directory = My.Settings.MeditechDirectory
        .MIS = My.Settings.MeditechMIS
        .Segment = My.Settings.MeditechSeg
        .MeditechPort = My.Settings.MeditechPort
        .MeditechIP = My.Settings.MeditechIP
    End With


    Monitor = New Monitor(Of PageAction)(New MeditechOutbound(mediInfo, New HCIFileStore))

MeditechOutb​​ound 和 HCIFileStore 都是接口的实现。

Public Class Monitor(Of TDocModel)
Public Property Outbound As IHISOutbound(Of TDocModel)

…
Public Class MeditechOutbound
Implements IHISOutbound(Of PageAction)

Public Property MeditechInfo As MeditechInfo
Public Property Store As IFileStore

我想要的是看起来像这样的配置:

 <Monitor of="PageAction">
     <Outbound type="assembly.namespace.MeditechOutbound">
            <MeditechInfo type="...MeditechInfo" MeditechIP="127.0.0.1"..../>
     </Outbound>
     <Store type="...HCIFileStore"/>
</Monitor>

我真的没有任何方法可以保证今后,说 IHISOOutbound 的任何其他实现都将有两个构造函数参数等 - 所以我不能只写一个 configSection 并做出假设 - 我从哪里开始?

标签: .netvb.netdependency-injectionapp-config

解决方案


推荐阅读