/// <summary> /// Registers the type. /// </summary> /// <param name="useConfig">if set to <c>true</c> [use config].</param> /// <exception cref="System.NotImplementedException"></exception> public void RegisterType(bool useConfig) { Assembly tempAsm = null; var notFound = new List <string>(); Type concrete = null, abstraction = null; var config = ConfigurationManager.GetSection(Consts.ConfigSectionName) as ConfigReader; if (AreRegistrationsAndMappingsOk(config.Registrations, config.Mappings)) { var mappings = config.Mappings.Cast <MappingConfigElement>(); var registrations = config.Registrations.Cast <RegistrationConfigElement>(); registrations.ToList().ForEach(x => { var newRegistration = new TypeInformation() { Name = x.Name }; var mapping = mappings.FirstOrDefault(z => z.Abstraction.Equals(x.Name, StringComparison.OrdinalIgnoreCase)); if (mapping != null) { bool instanceRequired, isPrejittingEnabled; newRegistration.LifeSpan = int.Parse(mapping.LifeSpan); bool.TryParse(mapping.InstanceRequired, out instanceRequired); bool.TryParse(config.PreJitting.Enabled, out isPrejittingEnabled); if (!string.IsNullOrEmpty(x.AssemblyFQN) && // Let's ensure the assembly specified exists (tempAsm = Dependencies.FirstOrDefault(y => y.FullName.Equals(x.AssemblyFQN, StringComparison.OrdinalIgnoreCase))) != null) { concrete = FindFirstConcreteImplementation(mapping.Abstraction, mapping.To, out abstraction); newRegistration.Abstraction = abstraction; } else { // Otherwise, we'll find the first occurrence of a type implementing the specified interface concrete = FindFirstConcreteImplementation(mapping.Abstraction, mapping.To, out abstraction); newRegistration.Abstraction = abstraction; } RegistrationHelper(newRegistration, concrete, instanceRequired, isPrejittingEnabled, null); } else { notFound.Add(string.Format(Consts.MappingInformationMissing, x.Name)); } }); InstanceSpanManager(mappings); // If there's been errors, we'll notify by throwing an exception if (notFound.Count > 0) { throw new NotSupportedException(notFound.TokenizeItemsInList(Consts.GenericMappingErrorSummary)); } } else { throw new ArgumentException(Consts.MappingRegistrationMismatch); } }