using Chloe.Entity; using Chloe.Infrastructure.Interception; using Chloe.Infrastructure; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Text; using System.Threading.Tasks; namespace DB { public class MappingHelper { public static IEntityTypeBuilder[] FindMapsFromAssembly(Assembly assembly) { var typeOf_IMap = typeof(IEntityTypeBuilder); var mapTypes = assembly.GetTypes().Where(a => a.IsClass && !a.IsAbstract && typeOf_IMap.IsAssignableFrom(a)) .ToList(); var maps = mapTypes.Select(a => (IEntityTypeBuilder)Activator.CreateInstance(a)); return maps.ToArray(); } } public static class DbInfo { public static void Init() { IDbCommandInterceptor interceptor = new DbCommandInterceptor(); DbInterception.Add(interceptor); } public static void Init(Assembly assembly) { Init(); var findMapsFromAssembly = MappingHelper.FindMapsFromAssembly(assembly); DbConfiguration.UseTypeBuilders(findMapsFromAssembly); } public static void Init(List assemblys) { List list = new List(); foreach (var assembly in assemblys) { var findMapsFromAssembly = MappingHelper.FindMapsFromAssembly(assembly); list.AddRange(findMapsFromAssembly); } DbConfiguration.UseTypeBuilders(list.ToArray()); } } }