Ejemplo n.º 1
0
        static ConfigurationManager()
        {
            var files = new DirectoryInfo(ApplicationManager.ApplicationExecutableDirectory).GetFiles("*.dll", SearchOption.AllDirectories).Where(c =>
            {
                var matched = ConfigurationOptions.DefaultConfigureFileMatchPattern switch
                {
                    DefaultConfigureFileMatchPattern.None => true,
                    DefaultConfigureFileMatchPattern.Default => !ConfigurationOptions.ConfigurationExcludeFileRegex.IsMatch(c.FullName),
                    DefaultConfigureFileMatchPattern.Convention => conventionFileNames.Any(kw => c.Name.Contains(kw)),
                    DefaultConfigureFileMatchPattern.IncludeFileName => ConfigurationOptions.DefaultConfigureFileNameMatchKeyWords?.Any(kw => c.Name.Contains(kw)) ?? false,
                    DefaultConfigureFileMatchPattern.ExcludeFileName => !(ConfigurationOptions.DefaultConfigureFileNameMatchKeyWords?.Any(kw => c.Name.Contains(kw)) ?? false),
                    _ => true
                };
                return(matched);
            });
            List <Type> allTypes = new List <Type>();

            foreach (var file in files)
            {
                try
                {
                    var types = Assembly.LoadFrom(file.FullName).GetTypes();
                    foreach (var type in types)
                    {
                        if (type.IsInterface)
                        {
                            continue;
                        }
                        var  baseType = type.BaseType;
                        bool isEntity = false;
                        if (baseType != null && baseType.IsGenericType)
                        {
                            //Entity
                            var genericType = baseType.GetGenericTypeDefinition();
                            if (genericType == entityGenericType)
                            {
                                isEntity = true;
                                Entity.ConfigureEntity(type);
                            }
                        }
                        //query model
                        var queryModelInterface = type.GetInterface(queryModelGenericType.Name);
                        if (queryModelInterface != null && !isEntity)
                        {
                            QueryModel.ConfigureQueryModelRelationEntity(type);
                        }
                        //module configuration
                        if (moduleConfigurationType.IsAssignableFrom(type))
                        {
                            IModuleConfiguration moduleConfiguration = Activator.CreateInstance(type) as IModuleConfiguration;
                            moduleConfiguration?.Init();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.LogError(ex, ex.Message);
                }
            }
        }
Ejemplo n.º 2
0
        static InternalConfigurationManager()
        {
            var files = ConfigurationManager.GetMatchedFiles();
            IEnumerable <Type> allTypes = Array.Empty <Type>();

            foreach (var file in files)
            {
                try
                {
                    var types = Assembly.LoadFrom(file.FullName).GetTypes();
                    allTypes = allTypes.Union(types);
                    foreach (var type in types)
                    {
                        if (type.IsInterface)
                        {
                            continue;
                        }
                        var  baseType = type.BaseType;
                        bool isEntity = false;
                        if (baseType != null && baseType.IsGenericType)
                        {
                            //Entity
                            var genericType = baseType.GetGenericTypeDefinition();
                            if (genericType == entityGenericType)
                            {
                                isEntity = true;
                                ConfigurationManager.Entity.ConfigureEntity(type);
                            }
                        }
                        //query model
                        var queryModelInterface = type.GetInterface(queryModelGenericType.Name);
                        if (queryModelInterface != null && !isEntity)
                        {
                            ConfigurationManager.QueryModel.ConfigureQueryModelRelationEntity(type);
                        }
                        //module configuration
                        if (moduleConfigurationType.IsAssignableFrom(type))
                        {
                            IModuleConfiguration moduleConfiguration = Activator.CreateInstance(type) as IModuleConfiguration;
                            moduleConfiguration?.Init();
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogManager.LogError(ex, ex.Message);
                }
            }

            //Object map
            if (ConfigurationManager.Setting.MapperBuilder != null)
            {
                ObjectMapper.Current = ConfigurationManager.Setting.MapperBuilder.CreateMapper(allTypes);
            }
        }