Exemplo n.º 1
0
        public dynamic BindServiceContext(IServiceContext serviceContext, string bindingName = null)
        {
            if (bindingName == null)
            {
                bindingName = GetType().Name;
            }
            ServiceContext = serviceContext;
            if (RebindMode == RebindMode.REBIND_IGNORE && serviceContext.Has(bindingName))
            {
                return(ServiceContext.Fetch(bindingName));
            }

            if (RebindMode == RebindMode.REBIND_REINITIALIZE && serviceContext.Has(bindingName))
            {
                IService oldService = serviceContext.Fetch(bindingName);
                oldService.Cease();
            }

            try {
                serviceContext.Bind(bindingName, this, true);
            }
            catch (ServiceDoubleBindException e)
            {
                Debug.Log("Error: Cannot bind two services to " + bindingName + " " + e);
                return(this);
            }

            return(this);
        }