Service Recomposition

Sep 3, 2010 at 3:17 PM

Hi, 

I have a WCF service and I'm adding it to MEF by doing this: 

        public void ResolveInstance(EndpointAddress address, ref CompositionBatch batch)
        {
            _serviceInstance = ChannelFactory<T>.CreateChannel(new NetTcpBinding(), address);            
            batch.AddExportedValue<T>(_serviceInstance); 
            
        }

And here's the scenario: 

I call this method on start up. I should also call this method whenever there's been changes in the address. therefore I have to recreate the channel and recompose the ExportedValue.

How will I be able to recompose this?

Sep 8, 2010 at 5:27 PM

Create a container per service request basis, that's perfectly fine, and that way you don't really need recomposition at all. Just create a new CompositionContainer and populate that with necessary exports as you go.

Sep 9, 2010 at 4:38 AM
leidegre wrote:

Create a container per service request basis, that's perfectly fine, and that way you don't really need recomposition at all. Just create a new CompositionContainer and populate that with necessary exports as you go.

What will happen to the previously created instance with the wrong address? Will it be overwritten or will it stay there? 

Sep 11, 2010 at 1:21 PM

It will go away because you're not really meant to share the containers cross requests. This is all about figuring out the life-time management of objects. In a REST based services that's typically on a per request basis. The address should not be able to change within the same request.