How to create a Singleton WCF proxy using Structuremap

In WCF, creating a proxy server is a difficult operation, so if you are faced with a performance slowdown, you should definitely look at this area. One possible solution to this problem is to reuse your proxies in your application streams, or to implement a singleton or pool

from the Javi Blog on creating a WCF proxy as a singleton using Castle . Can someone execute an implementation using Structuremap?

+3
source share
1 answer

This is pretty simple with StructureMap, and even if you need to do some testing, this should work:

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");
                    });
            }
        );

(HybridHttpOrThreadLocalScoped)

Resolve:

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

All Articles