public void Install(ServiceHost serviceHost, IKernel kernel, IWcfBurden burden) { object extension = GetInstance(kernel, burden); if (extension is IServiceBehavior) { serviceHost.Description.Behaviors.Add((IServiceBehavior)extension); } else if (extension is IServiceHostAware) { WcfUtils.BindServiceHostAware(serviceHost, (IServiceHostAware)extension, true); } else if (extension is IErrorHandler) { WcfUtils.RegisterErrorHandler(serviceHost, (IErrorHandler)extension, true); } else if (extension is IExtension <ServiceHostBase> ) { serviceHost.Extensions.Add((IExtension <ServiceHostBase>)extension); } else { WcfUtils.AttachExtension(serviceHost.Description.Behaviors, extension); } }
public void Install(ServiceEndpoint endpoint, bool withContract, IKernel kernel, IWcfBurden burden) { var extension = GetInstance(kernel, burden); if (extension is IEndpointBehavior) { endpoint.Behaviors.Add((IEndpointBehavior)extension); } else if (extension is IOperationBehavior) { if (withContract) { foreach (var operation in endpoint.Contract.Operations) { operation.Behaviors.Add((IOperationBehavior)extension); } } } else if (extension is IContractBehavior) { if (withContract) { endpoint.Contract.Behaviors.Add((IContractBehavior)extension); } } else if (extension is IErrorHandler) { WcfUtils.RegisterErrorHandler(endpoint, (IErrorHandler)extension, true); } else if (WcfUtils.AttachExtension(endpoint.Behaviors, extension) == false) { if (withContract && !WcfUtils.AttachExtension(endpoint.Contract.Behaviors, extension)) { Type owner = null; if (WcfUtils.IsExtension(extension, ref owner)) { if (typeof(IOperationBehavior).IsAssignableFrom(owner)) { foreach (var operation in endpoint.Contract.Operations) { WcfUtils.AttachExtension(operation.Behaviors, extension, owner); } } } } } }