Example #1
0
        /// <summary>
        /// Allows you to configure a base kernel of a particular name
        /// </summary>
        /// <param name="kernelName">name of the kernel being configured</param>
        /// <param name="registrationDelegate">registration delegate to call configure with</param>
        public void Configure(string kernelName, ExportRegistrationDelegate registrationDelegate)
        {
            InjectionKernel kernel;

            if (!kernels.TryGetValue(kernelName, out kernel))
            {
                if (rootScope == null)
                {
                    throw new Exception("SetRootScope must be called before configuring any named kernels");
                }

                kernel = new InjectionKernel(this, rootScope, null, kernelName, comparer);

                lock (kernelsLock)
                {
                    Dictionary<string, InjectionKernel> newKernels = new Dictionary<string, InjectionKernel>(kernels);

                    newKernels[kernelName] = kernel;

                    kernels = newKernels;
                }
            }

            kernel.Configure(registrationDelegate);
        }
Example #2
0
 /// <summary>
 /// Configure container
 /// </summary>
 /// <param name="registrationBlock">registration block</param>
 public void Configure(ExportRegistrationDelegate registrationBlock)
 {
     Container.Configure(registrationBlock);
 }
Example #3
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;
        }