Example #1
0
        public SubContainerCreatorByInstaller(
            DiContainer container,
            SubContainerCreatorBindInfo containerBindInfo,
            Type installerType,
            IEnumerable <TypeValuePair> extraArgs)
        {
            _installerType     = installerType;
            _container         = container;
            _extraArgs         = extraArgs.ToList();
            _containerBindInfo = containerBindInfo;

            Assert.That(installerType.DerivesFrom <InstallerBase>(),
                        "Invalid installer type given during bind command.  Expected type '{0}' to derive from 'Installer<>'", installerType);
        }
        public ScopeConcreteIdArgConditionCopyNonLazyBinder ByInstaller(Type installerType)
        {
            Assert.That(installerType.DerivesFrom <InstallerBase>(),
                        "Invalid installer type given during bind command.  Expected type '{0}' to derive from 'Installer<>'", installerType);

            var subcontainerBindInfo = new SubContainerCreatorBindInfo();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByInstaller(
                        container, subcontainerBindInfo, installerType, BindInfo.Arguments), false);

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #3
0
        public ScopeConcreteIdArgConditionCopyNonLazyBinder ByMethod(
#if !NET_4_6
            ModestTree.Util.
#endif
            Action <DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5> installerMethod)
        {
            var subcontainerBindInfo = new SubContainerCreatorBindInfo();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByMethod <TParam1, TParam2, TParam3, TParam4, TParam5>(
                        container, subcontainerBindInfo, installerMethod), false);

            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
        }
Example #4
0
        ByMethod(Action <DiContainer> installerMethod)
        {
            var subContainerBindInfo = new SubContainerCreatorBindInfo();

            SubFinalizer = new SubContainerBindingFinalizer(
                _bindInfo, _subIdentifier, _resolveAll,
                (container) => new SubContainerCreatorByMethod(container, subContainerBindInfo, installerMethod));

            return(new
#if NOT_UNITY3D
                   WithKernelScopeConcreteIdArgConditionCopyNonLazyBinder
#else
                   WithKernelDefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder
#endif
                       (subContainerBindInfo, _bindInfo));
        }
        ByMethod(Action <DiContainer, TParam1> installerMethod)
        {
            var subcontainerBindInfo = new SubContainerCreatorBindInfo();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByMethod <TParam1>(
                        container, subcontainerBindInfo, installerMethod), false);

#if NOT_UNITY3D
            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
#else
            return(new DefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder(subcontainerBindInfo, BindInfo));
#endif
        }
Example #6
0
        ByInstaller(Type installerType)
        {
            Assert.That(installerType.DerivesFrom <InstallerBase>(),
                        "Invalid installer type given during bind command.  Expected type '{0}' to derive from 'Installer<>'", installerType);

            var subContainerBindInfo = new SubContainerCreatorBindInfo();

            SubFinalizer = new SubContainerBindingFinalizer(
                _bindInfo, _subIdentifier, _resolveAll,
                (container) => new SubContainerCreatorByInstaller(container, subContainerBindInfo, installerType));

            return(new
#if NOT_UNITY3D
                   WithKernelScopeConcreteIdArgConditionCopyNonLazyBinder
#else
                   WithKernelDefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder
#endif
                       (subContainerBindInfo, _bindInfo));
        }
        public static void ApplyBindSettings(
            SubContainerCreatorBindInfo subContainerBindInfo, DiContainer subContainer)
        {
            if (subContainerBindInfo.DefaultParentName != null)
            {
#if !ZEN_TESTS_OUTSIDE_UNITY && !NOT_UNITY3D
                var defaultParent = new GameObject(
                    subContainerBindInfo.DefaultParentName);

                defaultParent.transform.SetParent(
                    subContainer.InheritedDefaultParent, false);

                subContainer.DefaultParent = defaultParent.transform;

                subContainer.Bind <IDisposable>()
                .To <DefaultParentObjectDestroyer>().AsCached().WithArguments(defaultParent);

                // Always destroy the default parent last so that the non-monobehaviours get a chance
                // to clean it up if they want to first
                subContainer.BindDisposableExecutionOrder <DefaultParentObjectDestroyer>(int.MinValue);
#endif
            }

            if (subContainerBindInfo.CreateKernel)
            {
                var parentContainer = subContainer.ParentContainers.OnlyOrDefault();
                Assert.IsNotNull(parentContainer, "Could not find unique container when using WithKernel!");

                if (subContainerBindInfo.KernelType != null)
                {
                    parentContainer.Bind(typeof(Kernel).Interfaces()).To(subContainerBindInfo.KernelType)
                    .FromSubContainerResolve()
                    .ByInstance(subContainer).AsCached();
                    subContainer.Bind(subContainerBindInfo.KernelType).AsCached();
                }
                else
                {
                    parentContainer.BindInterfacesTo <Kernel>().FromSubContainerResolve()
                    .ByInstance(subContainer).AsCached();
                    subContainer.Bind <Kernel>().AsCached();
                }
            }
        }
Example #8
0
        ByMethod(
#if !NET_4_6
            ModestTree.Util.
#endif
            Action <DiContainer, TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10> installerMethod)
        {
            var subcontainerBindInfo = new SubContainerCreatorBindInfo();

            ProviderFunc =
                (container) => new SubContainerDependencyProvider(
                    ContractType, SubIdentifier,
                    new SubContainerCreatorByMethod <TParam1, TParam2, TParam3, TParam4, TParam5, TParam6, TParam7, TParam8, TParam9, TParam10>(
                        container, subcontainerBindInfo, installerMethod), false);

#if NOT_UNITY3D
            return(new ScopeConcreteIdArgConditionCopyNonLazyBinder(BindInfo));
#else
            return(new DefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder(subcontainerBindInfo, BindInfo));
#endif
        }
 public WithKernelDefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder(
     SubContainerCreatorBindInfo subContainerBindInfo, BindInfo bindInfo)
     : base(subContainerBindInfo, bindInfo)
 {
 }
Example #10
0
 public SubContainerCreatorByMethodBase(
     DiContainer container, SubContainerCreatorBindInfo containerBindInfo)
 {
     _container         = container;
     _containerBindInfo = containerBindInfo;
 }
Example #11
0
 public WithKernelScopeConcreteIdArgConditionCopyNonLazyBinder(
     SubContainerCreatorBindInfo subContainerBindInfo, BindInfo bindInfo)
     : base(bindInfo)
 {
     _subContainerBindInfo = subContainerBindInfo;
 }
 public DefaultParentScopeConcreteIdArgConditionCopyNonLazyBinder(
     SubContainerCreatorBindInfo subContainerBindInfo, BindInfo bindInfo)
     : base(bindInfo)
 {
     SubContainerCreatorBindInfo = subContainerBindInfo;
 }