Пример #1
0
        /// <summary>
        /// Registers a type with a name. When Resolve is called, a new object will
        /// be create.
        /// </summary>
        /// <param name="interfaceType"></param>
        /// <param name="type"></param>
        /// <param name="name"></param>
        public void RegisterType(Type interfaceType, Type type, string name)
        {
            if (interfaceType == null)
            {
                throw new ArgumentNullException("interfaceType");
            }
            if (type == null)
            {
                throw new ArgumentNullException("type");
            }
            if (IsNameNullOrValid(name) == false)
            {
                throw new ArgumentNullException("name");
            }

            var typeAndName = new TypeAndName(interfaceType, name);

            // Cleanup previous stored services, with the same interface type and name.
            CleanupServices(interfaceType, name);

            // Add the typeAndName/type or update a previous registered type, with the same
            // typeAndName.
            RegisteredTypes.AddOrUpdate(typeAndName, k => type, (k, v) => type);
        }