protected void ControlRemoteObject(object instance, object value, PropertyInfo propertyInfo)
        {
            // Not letting mono behaviours to be injected if they are not IDIClosedContext
            // (because we cannot control their lifetime)

            IDIClosedContext ctxval = value as IDIClosedContext;

            if (RemoteObjectsHelper.IsRemoteObject(value) && (ctxval == null || !ctxval.IsValid()))
            {
                throw new MiniocException("Injecting a remote object that doesn't implement IDIClosedContext is not allowed ! Tried to inject object " + value + " into property " + propertyInfo.Name + " of the object " + instance);
            }
        }
Example #2
0
        public object Resolve()
        {
            object obj = instantiationFactory();

            // Saving the binding descriptor on resolved object
            IDIClosedContext cctx = obj as IDIClosedContext;

            if (cctx != null && cctx.IsValid())
            {
                cctx.descriptor.bindingDescriptor = this;
            }

            return(obj);
        }
Example #3
0
        private void InjectDependenciesInternal(object instance, Func <IConstruction> construction)
        {
            if (instance == null)
            {
                return;
            }

            // We need to call getInjectionStrategies early here so we can through exception if e.g. there are Injection attributes, but the object is not IDIClosedContext
            var strategies = _injector.getInjectionStrategies(instance);

            // Not injecting any dependencies if the object is not context object
            IDIClosedContext stateInstance = instance as IDIClosedContext;

            if (stateInstance == null || !stateInstance.IsValid())
            {
                RegisterRemoteObject(instance, true);
                return;
            }

            IBinding descriptor = stateInstance.descriptor.bindingDescriptor;

            if (descriptor == null)
            {
                throw new MindiException("Called inject dependencies on an instance that has no binding descriptor set: " + instance);
            }

            // If this instance is concrete on another layer, we inject dependencies on its own layer only, to avoid subjectivization
            if (descriptor.instantiationType == InstantiationType.Concrete && descriptor.context != this)
            {
                descriptor.context.InjectDependencies(instance, construction);
                return;
            }

            if (stateInstance.descriptor.diState == DIState.NotResolved)
            {
                stateInstance.descriptor.diState = DIState.Resolving;
                _injector.injectDependencies(instance, strategies, construction);
                RegisterRemoteObject(instance);
                stateInstance.AfterInjection();
                stateInstance.descriptor.diState = DIState.Resolved;
            }
        }