Autofac with wcf

   builder.Register(c => new ChannelFactory<IBuildingInfoService>
    ("BasicHttpBinding_IBuildingInfoService"))
                .SingleInstance();


    builder.Register(c => c
    .Resolve<ChannelFactory<IBuildingInfoService>>().CreateChannel())
               .As<IBuildingInfoService>()
               .UseWcfSafeRelease();

      

I have these lines of code in dependency injection for a WCF client.

Can someone explain how this works ??

How does one instance work?

What's going on with the Factory Channel?

+3


source to share


1 answer


SingleInstance

The above is creating a Singleton . Every time you request it, you will receive the same instance.

There are different ways to create a WCF client and one of them is Factory . The Channel Factory class is used to create a channel between client and server without creating a proxy.



When creating a Factory channel - it calls Open

internally.

You can see the source code here , and if you dig deep CreateChannel

into it, it ultimately calls EnsuredOpen

.

    protected void EnsureOpened()
    { 
        base.ThrowIfDisposed();
        if (this.State != CommunicationState.Opened)
        {
            lock (this.openLock) 
            {
                if (this.State != CommunicationState.Opened) 
                { 
                    this.Open();
                } 
            }
        }
    }

      

+2


source







All Articles