Пример #1
0
        private static TService FindAndCreateConfiguredType <TService>(IEnumerable <TypeMapping> configuredTypeMappings)
            where TService : class
        {
            TypeMapping mapping = FindMappingForType <TService>(configuredTypeMappings);

            if (mapping == null)
            {
                return(null);
            }

            return((TService)ActivatingServiceLocator.CreateInstanceFromTypeMapping(mapping));
        }
Пример #2
0
        /// <summary>
        /// Loads the type mappings.
        /// </summary>
        /// <param name="serviceLocator">The service locator.</param>
        /// <param name="typeMappings">The mappings.</param>
        public void LoadTypeMappings(IServiceLocator serviceLocator, IEnumerable <TypeMapping> typeMappings)
        {
            if (serviceLocator == null)
            {
                throw new ArgumentNullException("serviceLocator");
            }

            ActivatingServiceLocator activatingServiceLocator = serviceLocator as ActivatingServiceLocator;

            if (activatingServiceLocator == null)
            {
                throw new ArgumentException("serviceLocator must be a ActivatingServiceLocator, not a " + serviceLocator.GetType().Name, "serviceLocator");
            }

            if (typeMappings == null)
            {
                return;
            }

            foreach (TypeMapping typeMapping in typeMappings)
            {
                activatingServiceLocator.RegisterTypeMapping(typeMapping);
            }
        }
Пример #3
0
        /// <summary>
        /// Create the <see cref="IServiceLocator"/> and loads it with type mappings.
        /// </summary>
        /// <returns>The created service locator</returns>
        public IServiceLocator Create()
        {
            ActivatingServiceLocator serviceLocator = new ActivatingServiceLocator();

            return(serviceLocator);
        }