コード例 #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
        public Func <IKernelInternal, IReleasePolicy, object> SelectComponent(MethodInfo method, Type type, object[] arguments)
        {
            return((k, p) =>
            {
                string key = null;
                var argument = arguments[0];

                if (arguments.Length == 2)
                {
                    key = (string)argument;
                    argument = arguments[1];
                }
                else if (argument is string)
                {
                    return k.Resolve((string)argument, method.ReturnType, null, p);
                }

                if (argument is Uri)
                {
                    argument = WcfEndpoint.At((Uri)argument);
                }

                var args = new Arguments {
                    { Guid.NewGuid().ToString(), argument }
                };

                if (key == null)
                {
                    return k.Resolve(method.ReturnType, args, p);
                }

                return k.Resolve(key, method.ReturnType, args, p);
            });
        }
コード例 #3
0
            public override object Resolve(IKernel kernel)
            {
                string key      = null;
                var    argument = arguments[0];

                if (arguments.Length == 2)
                {
                    key      = (string)argument;
                    argument = arguments[1];
                }
                else if (argument is string)
                {
                    return(kernel.Resolve((string)argument, ComponentType));
                }

                if (argument is Uri)
                {
                    argument = WcfEndpoint.At((Uri)argument);
                }

                var args = new HybridDictionary {
                    { Guid.NewGuid().ToString(), argument }
                };

                if (key == null)
                {
                    return(kernel.Resolve(ComponentType, args));
                }

                return(kernel.Resolve(key, ComponentType, args));
            }
コード例 #4
0
ファイル: WcfClientExtension.cs プロジェクト: javanal/Windsor
        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);
        }
コード例 #5
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);
        }
コード例 #6
0
 public RestClientModel(Uri remoteAddress)
     : this(WcfEndpoint.At(remoteAddress))
 {
 }