Пример #1
0
        public IRegistration Load(string key, Type service, Arguments arguments)
        {
            if (service == typeof(IWcfClientFactory))
            {
                throw new FacilityException(
                          "The IWcfClientFactory is only available with the TypedFactoryFacility.  " +
                          "Did you forget to register that facility? Also make sure that TypedFactoryFacility was registred before WcfFacility.");
            }

            if (service == null || WcfUtils.IsServiceContract(service) == false)
            {
                return(null);
            }

            var clientModel = WcfUtils.FindDependencies <IWcfClientModel>(arguments)
                              .FirstOrDefault() ?? new DefaultClientModel();

            var endpoint = WcfUtils.FindDependencies <IWcfEndpoint>(arguments).FirstOrDefault();

            if (endpoint != null)
            {
                clientModel = clientModel.ForEndpoint(endpoint);
            }
            else if (clientModel.Endpoint == null && string.IsNullOrEmpty(key) == false)
            {
                clientModel = clientModel.ForEndpoint(WcfEndpoint.FromConfiguration(key));
            }

            return(Component.For(service).Named(key).LifeStyle.Transient.AsWcfClient(clientModel));
        }
Пример #2
0
        private static IWcfClientModel ObtainClientModel(ComponentModel model, CreationContext context)
        {
            var clientModel = WcfUtils.FindDependencies <IWcfClientModel>(context.AdditionalArguments).FirstOrDefault();
            var endpoint    = WcfUtils.FindDependencies <IWcfEndpoint>(context.AdditionalArguments).FirstOrDefault();

            if (endpoint != null)
            {
                if (clientModel == null)
                {
                    clientModel = ObtainClientModel(model);
                }

                clientModel = clientModel.ForEndpoint(endpoint);
            }

            return(clientModel);
        }
Пример #3
0
        private static IEnumerable <IWcfServiceModel> ResolveServiceModels(ComponentModel model)
        {
            bool foundOne = false;

            if (model.Implementation.IsClass && !model.Implementation.IsAbstract)
            {
                foreach (var serviceModel in WcfUtils.FindDependencies <IWcfServiceModel>(model.CustomDependencies))
                {
                    foundOne = true;
                    yield return(serviceModel);
                }

                if (foundOne == false && model.Configuration != null && "true" == model.Configuration.Attributes[WcfConstants.ServiceHostEnabled])
                {
                    yield return(new DefaultServiceModel());
                }
            }
        }
Пример #4
0
        private static IWcfServiceModel SelectBestHostedServiceModel(ComponentModel model)
        {
            IWcfServiceModel serviceModel = null;

            foreach (var candidateServiceModel in WcfUtils.FindDependencies <IWcfServiceModel>(model.CustomDependencies, WcfUtils.IsHosted))
            {
                if (candidateServiceModel is M)
                {
                    serviceModel = candidateServiceModel;
                    break;
                }
                else
                {
                    serviceModel = serviceModel ?? candidateServiceModel;
                }
            }

            return(serviceModel);
        }
Пример #5
0
        private static IWcfClientModel ResolveClientModel(ComponentModel model)
        {
            var clientModel = WcfUtils.FindDependencies <IWcfClientModel>(model.CustomDependencies).FirstOrDefault();

            if (clientModel == null && model.Configuration != null)
            {
                var endpointConfiguration = model.Configuration.Attributes[WcfConstants.EndpointConfiguration];

                if (string.IsNullOrEmpty(endpointConfiguration) == false)
                {
                    clientModel = new DefaultClientModel(WcfEndpoint.FromConfiguration(endpointConfiguration));
                }
            }

            if (clientModel != null)
            {
                ObtainServiceContract(model, clientModel);
            }

            return(clientModel);
        }
Пример #6
0
        private static IWcfClientModel ResolveClientModel(ComponentModel model)
        {
            if (model.Service.IsInterface)
            {
                var clientModel = WcfUtils.FindDependencies <IWcfClientModel>(model.CustomDependencies).FirstOrDefault();
                if (clientModel != null)
                {
                    return(clientModel);
                }
            }

            if (model.Configuration != null)
            {
                var endpointConfiguration =
                    model.Configuration.Attributes[WcfConstants.EndpointConfiguration];

                if (!string.IsNullOrEmpty(endpointConfiguration))
                {
                    return(new DefaultClientModel(WcfEndpoint.FromConfiguration(endpointConfiguration)));
                }
            }

            return(null);
        }