public InsqlResolverFactory(IServiceProvider serviceProvider)
        {
            this.serviceProvider = serviceProvider;

            this.descriptorLoader = serviceProvider.GetRequiredService <IInsqlDescriptorLoader>();
            this.resolveMatcher   = serviceProvider.GetRequiredService <IInsqlResolveMatcher>();
            this.resolveFilters   = serviceProvider.GetServices <IInsqlResolveFilter>();

            this.insqlDescriptors   = this.descriptorLoader.Load();
            this.defaultDescriptors = new ConcurrentDictionary <Type, InsqlDescriptor>();
        }
示例#2
0
        private void LoadXmlEntityMaps(IInsqlDescriptorLoader descriptorLoader)
        {
            var mapSections = new Dictionary <Type, IInsqlMapSection>();

            var insqlDescriptors = descriptorLoader.Load().Values;

            foreach (var descriptor in insqlDescriptors)
            {
                foreach (var map in descriptor.Maps.Values)
                {
                    mapSections[map.Type] = map;
                }
            }

            var resultMaps = mapSections.Values.Select(mapSection =>
            {
                var entityMap = string.IsNullOrWhiteSpace(mapSection.Table) ?
                                new InsqlEntityMap(mapSection.Type) :
                                new InsqlEntityMap(mapSection.Type, mapSection.Table, mapSection.Schema);

                foreach (var mapElement in mapSection.Elements.Values)
                {
                    var propertyInfo = mapSection.Type.GetProperty(mapElement.Property);

                    if (propertyInfo == null)
                    {
                        throw new Exception($"insql entity type : {mapSection.Type} `{mapElement.Property}` property is not exist!");
                    }

                    entityMap.Properties.Add(new InsqlPropertyMap(propertyInfo, mapElement.Name)
                    {
                        IsIdentity = mapElement.Identity,
                        IsKey      = mapElement.ElementType == InsqlMapElementType.Key
                    });
                }

                InsqlEntityValidator.Instance.Validate(entityMap);

                return(entityMap);
            }).ToDictionary(item => item.EntityType, item => (IInsqlEntityMap)item);

            foreach (var itemMap in resultMaps)
            {
                this.entityMaps[itemMap.Key] = itemMap.Value;
            }
        }
示例#3
0
        public InsqlModel(IOptions <InsqlModelOptions> options, IInsqlDescriptorLoader descriptorLoader, IInsqlModelMapper entityMapper)
        {
            var optionsValue = options.Value;

            if (optionsValue.IncludeAnnotationMaps)
            {
                this.LoadAnnotationEntityMaps(optionsValue.IncludeAnnotationMapsAssemblies);
            }

            if (optionsValue.IncludeFluentMaps)
            {
                this.LoadFluentEntityMaps(optionsValue.IncludeFluentMapsAssemblies);
            }

            if (optionsValue.IncludeXmlMaps)
            {
                this.LoadXmlEntityMaps(descriptorLoader);
            }

            entityMapper.Mapping(this.entityMaps.Values);
        }