如何定义解析 json/xml 配置时使用的默认 Autofac 语言环境

How to define default Autofac locale used when parsing json/xml configuration

我正在尝试使用 xml 配置来配置 autofac,但 运行 遇到语言环境问题。我尝试注册的组件之一需要 double 参数,该参数在我本地系统上的格式为 xxx,yyy - 使用 comma 作为小数点分隔符。我必须使用的另一个系统使用 dot 作为小数点分隔符。有没有办法强制 autofac 忽略语言环境设置,只解析以点作为小数点分隔符的数字?

这个配置

<?xml version="1.0" encoding="utf-8" ?>
<autofac>
  <components name="0">
    <type>Geometry.SomeRule, Geometry</type>
    <services name="0" type="Geometry.IValidationRule, Geometry" />
    <parameters>
      <min>3.048</min>
      <max>4.572</max>
    </parameters>
  </components>
</autofac>

投掷

Autofac.Core.DependencyResolutionException: 'An exception was thrown while activating IValidationRule[] -> SomeRule.'
Inner exceptions: Exception: 3,048 is not a valid value for Double.

如果我使用逗号注册在我的设备上有效,但在其他设备上无效。

我可以通过在注册和容器构建期间设置 CurrentThread.CurrentCulture 来解决这个问题,但这对我来说似乎不是一个正确的解决方案。

您似乎发现了一个错误。 The TypeManipulation code that converts uses the implicit current culture rather than providing a culture. 那不是可以推翻的东西。

I've filed an issue on your behalf.