Example #1
0
        /// <summary>
        /// Configuration object constructor
        /// </summary>
        /// <param name="configuration"></param>
        /// <param name="parent"></param>
        /// <param name="name"></param>
        public InjectionScope(IInjectionScopeConfiguration configuration, IInjectionScope parent, string name) :
            base(parent, name, new ImmutableHashTree <Type, ActivationStrategyDelegate> [configuration.CacheArraySize])
        {
            configuration.SetInjectionScope(this);

            InternalFieldStorage.ScopeConfiguration = configuration;

            InternalFieldStorage.InjectionContextCreator = configuration.Implementation.Locate <IInjectionContextCreator>();

            InternalFieldStorage.CanLocateTypeService = configuration.Implementation.Locate <ICanLocateTypeService>();

            InternalFieldStorage.ActivationStrategyCompiler = configuration.Implementation.Locate <IActivationStrategyCompiler>();

            InternalFieldStorage.StrategyCollectionContainer =
                AddDisposable(configuration.Implementation.Locate <IActivationStrategyCollectionContainer <ICompiledExportStrategy> >());

            InternalFieldStorage.DecoratorCollectionContainer =
                AddDisposable(configuration.Implementation.Locate <IActivationStrategyCollectionContainer <ICompiledDecoratorStrategy> >());

            for (var i = 0; i <= ArrayLengthMinusOne; i++)
            {
                ActivationDelegates[i] = ImmutableHashTree <Type, ActivationStrategyDelegate> .Empty;
            }

            if (configuration.AutoRegisterUnknown && Parent == null)
            {
                InternalFieldStorage.MissingExportStrategyProviders =
                    InternalFieldStorage.MissingExportStrategyProviders.Add(
                        configuration.Implementation.Locate <IMissingExportStrategyProvider>());
            }

            if (configuration.SupportFuncType)
            {
                StrategyCollectionContainer.AddStrategy(new FuncTypeStrategy(this));
            }

            DisposalScopeProvider = configuration.DisposalScopeProvider;

            DisposalScope = DisposalScopeProvider == null ? this : null;
        }
Example #2
0
        /// <summary>
        /// Create a new Kernel of a particular name
        /// </summary>
        /// <param name="parentKernel">the parent kernel</param>
        /// <param name="kernelName">name of the kernel to create</param>
        /// <param name="registrationDelegate"></param>
        /// <param name="parentScopeProvider"></param>
        /// <param name="scopeProvider"></param>
        /// <returns></returns>
        public InjectionKernel CreateNewKernel(InjectionKernel parentKernel,
			string kernelName,
			ExportRegistrationDelegate registrationDelegate,
			IDisposalScopeProvider parentScopeProvider,
			IDisposalScopeProvider scopeProvider)
        {
            InjectionKernel newKernel;

            if (string.IsNullOrEmpty(kernelName))
            {
                IDisposalScopeProvider newScopeProvider = scopeProvider ?? parentScopeProvider;

                newKernel = new InjectionKernel(this, parentKernel, newScopeProvider, kernelName, comparer);
            }
            else
            {
                InjectionKernel foundKernel;

                if (kernels.TryGetValue(kernelName, out foundKernel))
                {
                    newKernel = foundKernel.Clone(parentKernel, parentScopeProvider, scopeProvider);
                }
                else
                {
                    IDisposalScopeProvider newScopeProvider = scopeProvider ?? parentScopeProvider;

                    newKernel = new InjectionKernel(this, parentKernel, newScopeProvider, kernelName, comparer);
                }
            }

            if (registrationDelegate != null)
            {
                newKernel.Configure(registrationDelegate);
            }

            return newKernel;
        }