private void RegisterEntityTypesNames()
        {
            var sources = _unityContainer.ResolveAll <IDataSource>();

            if (sources == null)
            {
                return;
            }

            foreach (var source in sources)
            {
                var sourceType = source.GetType();

                var type = typeof(IDataSource <>);

                var interfaceType =
                    sourceType.GetInterfaces()
                    .Where(_ => _.IsGenericType && (_.GetGenericTypeDefinition() == type))
                    .Select(_ => _.GetGenericArguments()[0])
                    .SingleOrDefault();

                if (interfaceType == null)
                {
                    continue;
                }

                var typeKey = interfaceType.Name;

                if (_queryEntityNameRepository.GetByKey(typeKey) != null)
                {
                    continue;
                }

                _queryEntityNameRepository.Insert
                (
                    new QueryEntityNames
                {
                    AssemblyName = sourceType.Assembly.FullName,
                    Key          = typeKey,
                    TypeName     = interfaceType.FullName
                });

                _queryEntityNameRepository.Save();
            }
        }
Пример #2
0
        public Type GetEntityType(string entityName)
        {
            if (string.IsNullOrEmpty(nameof(entityName)))
            {
                throw new ArgumentNullException(nameof(entityName));
            }

            var entityTypeInfo = _entityNameRepository.GetByKey(entityName);

            if (entityTypeInfo == null)
            {
                throw new UnknownQueryEntityTypeException(entityName);
            }

            var typeFullName = $"{entityTypeInfo.TypeName}, {entityTypeInfo.AssemblyName}";

            var entityType = Type.GetType(typeFullName);

            return(entityType);
        }