private DependencyDefinitionCollection(IUnityContainer unityContainer, MapperCollection parentMappings, string scopeName)
 {
     Ensure.NotNull(unityContainer, "unityContainer");
     this.isResolvable = requiredType => unityContainer.Registrations.Any(r => r.RegisteredType == requiredType);
     this.mapper       = new Mapper(unityContainer, parentMappings, scopeName);
     ScopeName         = scopeName;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Copies definitions from ancestors for current scope.
        /// </summary>
        /// <param name="mappings">Ancestor definitions.</param>
        /// <param name="scopeName">Current scope name.</param>
        private void CopyFromParentScope(MapperCollection mappings, string scopeName)
        {
            IEnumerable <DependencyDefinition> scopeMappings;

            if (mappings.TryGet(scopeName, out scopeMappings))
            {
                foreach (DependencyDefinition model in scopeMappings)
                {
                    Add(model);
                }
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates new instance for <paramref name="unityContainer"/> in scope <paramref name="scopeName"/>.
        /// If <paramref name="parentCollection"/> is <c>null</c>, thas mapper is the root one; otherwise this
        /// mapper inherits from <paramref name="parentCollection"/>.
        /// </summary>
        /// <param name="unityContainer">Unity container to insert definitions into.</param>
        /// <param name="parentCollection">Collection of definitions defined in parent scope.</param>
        /// <param name="scopeName">Scope name to associate with.</param>
        public Mapper(IUnityContainer unityContainer, MapperCollection parentCollection, string scopeName)
        {
            Ensure.NotNull(unityContainer, "unityContainer");
            Ensure.NotNullOrEmpty(scopeName, "scopeName");
            this.unityContainer = unityContainer;
            this.scopeName      = scopeName;

            if (parentCollection == null)
            {
                this.collection = new MapperCollection();
            }
            else
            {
                this.collection = new MapperCollection(parentCollection);
                CopyFromParentScope(parentCollection, scopeName);
            }
        }
 /// <summary>
 /// Creates collection that inherits from <paramref name="parentCollection"/>.
 /// </summary>
 /// <param name="parentCollection">Parent collectio of definitions.</param>
 public MapperCollection(MapperCollection parentCollection)
 {
     Ensure.NotNull(parentCollection, "parentCollection");
     this.parentCollection = parentCollection;
 }