1
Vote

Build up existing service and contract behaviors from the container

description

There is already functionality in the UnityServiceHost to inject new service and contract behaviors based on what's been defined within the container's configuration.

However, we had some behaviors added via old methods (attribute based) which would benefit from dependency injection.

We added the following functions:
        private void BuildUpExistingServiceBehaviors(IUnityContainer container)
        {
            foreach (var behavior in Description.Behaviors)
            {
                container.BuildUp(behavior.GetType(), behavior);
            }
        }

        private void BuildUpExistingContractBehaviors(IUnityContainer container)
        {
            foreach (var contractDescription in ImplementedContracts.Values)
            {
                container.BuildUp(contractDescription.GetType(), contractDescription);
            }
        }
And called them in the constructor immediately before the related ApplyServiceBehaviors and ApplyContractBehaviors function calls.

comments