gpt4 book ai didi

c# - 如何使用 Structuremap 创建单例 WCF 代理

转载 作者:行者123 更新时间:2023-11-30 18:39:14 24 4
gpt4 key购买 nike

In WCF, creating a proxy is a heavy operation, so if you are experiencing performance slowdown you should definitely look at this area. One of the possible solutions to tackle this problem is to reuse your proxies across your application threads, either implementing a singleton or a pool

来自 Javi's blog on creating WCF proxy as singleton using Castle .有人可以提供使用 Structuremap 的实现吗?

最佳答案

这对于 StructureMap 来说非常简单,即使您需要进行一些测试,这也应该可行:

ObjectFactory.Configure(
x =>
{
x.For<GetFilesService.Service1Client>().HybridHttpOrThreadLocalScoped().Use(ctx =>
{
// Setup logic goes here
return new GetFilesService.Service1Client("NetTcpBinding_IService1", "net.tcp://localhost:8089/test");
});
}
);

这里的秘诀是使用 Thread Local 作用域 (HybridHttpOrThreadLocalScoped)

然后解决:

var client = ObjectFactory.GetInstance<GetFilesService.Service1Client>();

关于c# - 如何使用 Structuremap 创建单例 WCF 代理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10308243/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com