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

标签 c# wcf dependency-injection structuremap

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/

相关文章:

带有 Windows 身份验证的 WCF jsonP - 可能吗?

c# - wcf restful服务配置错误

java - @EntityListeners 注入(inject) + jUnit 测试

c# - 实体类的依赖注入(inject)

c# - ListView 中的 WPF、MVVM、EventBehaviourFactory,将事件绑定(bind)到命令

C# - 从 DirectoryInfo 中删除某些文件

c# - Windows 8 Metro 中的爆竹类动画

c# - 每次迭代或循环浏览文档列表时如何创建新的 PDF 文件?

c# - WCF 传递文件流

java - 注入(inject)具有特定接口(interface)的所有 bean 列表