最近阅读了关于不可变集合的信息。当读取操作的执行频率高于写入操作时,建议将它们用作线程安全的读取操作。
然后我想测试读取性能ImmutableDictionary
与ConcurrentDictionary
. 这是这个非常简单的测试(在 .NET Core 2.1 中):
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
namespace ImmutableSpeedTests
{
class Program
{
public class ConcurrentVsImmutable
{
public int ValuesCount;
public int ThreadsCount;
private ImmutableDictionary<int, int> immutable = ImmutableDictionary<int, int>.Empty;
private ConcurrentDictionary<int, int> concurrent = new ConcurrentDictionary<int, int>();
public ConcurrentVsImmutable(int valuesCount, int threadsCount)
{
ValuesCount = valuesCount;
ThreadsCount = threadsCount;
}
public void Setup()
{
// fill both collections. I don't measure …
Run Code Online (Sandbox Code Playgroud) .net c# concurrency concurrent-collections immutable-collections
好吧,我知道这有点棘手。我有一个 ASP.NET Core 站点后端 ( site
),它facade
通过 http与另一个系统 ( ) 通信。
但不是与HttpClient
但与facade
提供HttpClient
底层的客户。
这些客户端的构造函数看起来像这样
public class OrdersClient : IOrdersClient
{
private HttpClient _client;
public OrdersClient(IEndpoint endpoint, HttpClient client)
{ ... }
}
Run Code Online (Sandbox Code Playgroud)
注册看起来像这样
services
.AddHttpClient("facade-client")
.AddHttpMessageHandler<CorrelationIdDelegatingHandler>()
.AddHttpMessageHandler<HttpErrorDelegatingHandler>()
.AddTypedClient<IOrdersClient>((endpoint, client) => new OrdersClient(endpoint, client));
Run Code Online (Sandbox Code Playgroud)
并且配置包含(这很重要!)
app.UseCorrelationId(new CorrelationIdOptions());
Run Code Online (Sandbox Code Playgroud)
NBendpoint
在这种情况下是什么并不重要。
好的。所以我想site
用全新的cool来测试我的WebApplicationFactory
。我创建它并site
按照文档中的描述获取客户端。对于某些测试,我只是模拟客户facade
喜欢
public TestOrdersClient: IOrdersClient
{
}
Run Code Online (Sandbox Code Playgroud)
并在没有facade
.
进入正题。我想测试处理程序装修我HttpClient
来facade
。
我想如何测试处理程序:我注册了假的 …
我刚刚开始研究F#并且不小心写了这个绑定
let List = 1
Run Code Online (Sandbox Code Playgroud)
现在当我尝试获取像'filter'这样的List方法时,我得到了这个错误
错误FS0039:未定义字段,构造函数或成员"过滤器".
当然使用完整类型名称的方法Microsoft.FSharp.Collections.List.filter
仍然有效.
我想知道为什么可以在F#中使用类型名称作为标识符,以及如何将名称List设置为从中键入List Microsoft.FSharp.Collections
.
当我试图像这样重新分配时
type List = Microsoft.FSharp.Collections.List<'T>
Run Code Online (Sandbox Code Playgroud)
我明白了
错误FS0039:未定义类型参数"T".
谢谢!
我正在 MacOS 上使用 JetBrains Rider,并使用 Scott Wlaschin 的代码进行实验:Domain Modeling Made Function
这是我的模块定义及其依赖项:
module internal DomainModeling.Domain.PlaceOrderWorkflow.Internal
open DomainModeling.Domain.Api
open DomainModeling.Domain.Primitives
open DomainModeling.Domain.Utils
Run Code Online (Sandbox Code Playgroud)
我想从这个模块生成签名文件。但我对使用 dotnet builder 或 fsharp 编译器感到困惑。如果我使用 dotnet 命令,我无法传递标志--sig 但如果我使用这样的 fsharp 编译器
fsharpc src/PlaceOrderWorkflow.fs --sig:PlaceOrderWorkflow.fsi
Run Code Online (Sandbox Code Playgroud)
我收到编译器错误。我想是因为它不知道我的依赖关系。像这样的错误
error FS0039: The namespace or module 'DomainModeling' is not defined.
Run Code Online (Sandbox Code Playgroud)
那么,请告诉我在这种情况下如何生成 *.fsi?