Например:
Код: Выделить всё
Key 1 => "api:BaseUrl:tenantId1", "www.tenant1.com"
Key 2 => "api:BaseUrl:tenantId2", "www.tenant2.com"
Key 3 => "api:BaseUrl:tenantId3", "www.tenant3.com"
Код: Выделить всё
Key Value
"api" null
"api:BaseUrl" null
"api:BaseUrl:tenantId1" "www.tenant1.com"

и когда я пытаюсь связать, он возвращает ноль
Код: Выделить всё
ApiOptions apiOptions = new ApiOptions();
configuration.Bind(apiOptions);
И когда я пытаюсь:
Код: Выделить всё
configuration.GetSection(nameof(ApiOptions)).Get();
Код: Выделить всё
"Cannot create instance of type 'System.String' because it has multiple public
parameterized constructors."
Код: Выделить всё
public class ApiOptions
{
public string BaseUrl { get; set; }
public string IntegrationUrl{ get; set; }
}
Код: Выделить всё
var inMemorySettings = new Dictionary
{
{"ApiOptions:BaseUrl:1ce1f5cc-7e01-4ee8-8e80-36e3e68405f3", "https://tenant1.lab.com"},
{"ApiOptions:IntegrationUrl:1ce1f5cc-7e01-4ee8-8e80-36e3e68405f3", "api/id"},
};
Код: Выделить всё
var configurationBuilder = new ConfigurationBuilder();
configurationBuilder.AddInMemoryCollection(inMemorySettings);
var configuration = configurationBuilder.Build();
configuration.Bind(apiOptions);
Код: Выделить всё
apiOptions
Вот строка, которая выдает исключение:
Код: Выделить всё
ApiOptions? apiOptions1 = configuration.GetSection(nameof(ApiOptions)).Get();
Подробнее здесь: https://stackoverflow.com/questions/788 ... to-options