是否可以配置 StructureMap,以便根据项目是在调试模式还是发布模式下构建来使用不同的 .config 设置?

发布于 2024-09-03 06:54:58 字数 592 浏览 3 评论 0原文

我知道,当我想将特定参数传递给对象的构造函数时,我可以在 StructureMap 中读取 *.config 文件(或它们引用的文件)。

ForRequestedType<IConfiguration>()
                .TheDefault.Is.OfConcreteType<SqlServerConfiguration>()
                .WithCtorArg("db_server_address")
                .EqualToAppSetting("data.db_server_address")

但我想做的是在调试模式下读取一个配置设置,在发布模式下读取另一个配置设置。

当然,我可以用 #if DEBUG 包围 .EqualToAppSetting("data.db_server_address"),但由于某种原因,当我将它们放入时,这些语句让我有点畏缩我想知道是否有某种方法可以使用 StructureMap 库本身来做到这一点。

那么我可以根据项目是在调试模式还是发布模式下构建来为我的对象提供不同的设置吗?

I know that in StructureMap I can read from my *.config files (or files referenced by them), when I want to pass specific arguments to an object's constructor.

ForRequestedType<IConfiguration>()
                .TheDefault.Is.OfConcreteType<SqlServerConfiguration>()
                .WithCtorArg("db_server_address")
                .EqualToAppSetting("data.db_server_address")

But what I would like to do is read from one config setting in debug mode and another in release mode.

Sure I could surround the .EqualToAppSetting("data.db_server_address"), with #if DEBUG, but for some reason those statements make me cringe a little when I put them in. I'd like to know if there was some way to do this with the StructureMap library itself.

So can I feed my objects different settings based on whether the project is built in debug or release mode?

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

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

发布评论

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

评论(1

小霸王臭丫头 2024-09-10 06:54:58

StructureMap 没有内置的“调试”或“发布”模式检测。

但是,当您通过其 DSL 以编程方式配置 StructureMap(在注册表中,或在容器上调用 Initialize() 或 Configure())时,您正在使用 C# 语言。您可以执行 C# 允许的任何操作。因此,您的问题变成“c# 中是否有一种方法可以在调试模式下有条件地以不同方式运行某些代码”,最明显的答案可能是让您感觉不好的条件编译指令。

StructureMap has no built-in detection of "debug" or "release" mode.

However, when you programmatically configure StructureMap via its DSL (in a Registry, or a call to Initialize() or Configure() on the container), you are using the C# language. You can do anything that C# allows. So your question becomes "is there a way in c# to conditionally run some code differently in debug mode", to which the most obvious answer will likely be the conditional compilation directives that make you feel bad.

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