我的appsettings.jsonaspnet vnext应用程序的文件中包含以下部分。
"Settings": {
"IgnoredServices" : ["ignore1", "ignore2"]
}
}
Run Code Online (Sandbox Code Playgroud)
这在使用映射时非常愉快IOptions<Settings>,其中settings类是
public class Settings
{
public List<string> IgnoredServices { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
但是,我正在努力用环境变量形式覆盖此json文件选项。我试过了
名称 Settings:IgnoredServices
值 "ignore1", "ignore2"
和
名称 Settings:IgnoredServices
值 ["ignore1", "ignore2"]
似乎都无法正确映射,并且出现以下错误消息
System.InvalidOperationException: Failed to convert '["ignore1", "ignore2"]'
to type 'System.Collections.Generic.List`1[System.String]
Run Code Online (Sandbox Code Playgroud)
我应该将值放入环境变量中以哪种格式才能成功解释为正确的字符串列表?
为什么这个代码(尝试)用第二个对象覆盖我的第一个对象?我的第一个对象具体为Id的"StringBasedIdClasses/1",第二个没有提供Id,所以Raven应该生成一个未使用的Id,不应该吗?
var quickStore = new EmbeddableDocumentStore() { RunInMemory = true };
quickStore.Initialize();
quickStore.RegisterListener(new DocumentConversionListener()).RegisterListener(new DocumentStoreListener());
using (var session = quickStore.OpenSession())
{
session.Advanced.UseOptimisticConcurrency = true;
var stringIdTest = new StringBasedIdClass()
{
Id = "StringBasedIdClasses/1",
Name = "StringItem1"
};
session.Store(stringIdTest);
session.SaveChanges();
}
using (var session = quickStore.OpenSession())
{
session.Advanced.UseOptimisticConcurrency = true;
var stringIdTest = new StringBasedIdClass()
{
Name = "DidIReplaceYou"
};
session.Store(stringIdTest);
session.SaveChanges();//This fails with a ConcurrencyViolation as I use OptimisticConcurrency and have Etag support on my objects
}
Run Code Online (Sandbox Code Playgroud)
一切都在使用文档存储的一个当前实例.这似乎很基本所以一定要错过一些简单的东西.
我正在尝试为任意代码编写一个包装器,在给定的超时期限后取消(或至少停止等待)代码。
我有以下测试和实现
[Test]
public void Policy_TimeoutExpires_DoStuff_TaskShouldNotContinue()
{
var cts = new CancellationTokenSource();
var fakeService = new Mock<IFakeService>();
IExecutionPolicy policy = new TimeoutPolicy(new ExecutionTimeout(20), new DefaultExecutionPolicy());
Assert.Throws<TimeoutException>(async () => await policy.ExecuteAsync(() => DoStuff(3000, fakeService.Object), cts.Token));
fakeService.Verify(f=>f.DoStuff(),Times.Never);
}
Run Code Online (Sandbox Code Playgroud)
和“DoStuff”方法
private static async Task DoStuff(int sleepTime, IFakeService fakeService)
{
await Task.Delay(sleepTime).ConfigureAwait(false);
var result = await Task.FromResult("bob");
var test = result + "test";
fakeService.DoStuff();
}
Run Code Online (Sandbox Code Playgroud)
以及 IExecutionPolicy.ExecuteAsync 的实现
public async Task ExecuteAsync(Action action, CancellationToken token)
{
var cts = new CancellationTokenSource();//TODO: resolve ignoring the …Run Code Online (Sandbox Code Playgroud)