protected void Initialise() { var entityTypes = _typeFinder.FindAll().Where(t => t.IsEntityType()) .Select(t => new { Type = t, TypeShortAlias = t.GetAttribute <EntityAttribute>()?.TypeShortAlias }) .ToList(); // check for duplicates var duplicates = entityTypes .Where(i => !string.IsNullOrWhiteSpace(i.TypeShortAlias)) .GroupBy(i => i.TypeShortAlias, (t, items) => new { TypeShortAlias = t, Types = items.Select(i => i.Type) }) .Where(g => g.Types.Count() > 1).ToList(); if (duplicates.Any()) { throw new DuplicatedTypeShortAliasesException(duplicates.ToDictionary(i => i.TypeShortAlias, i => i.Types)); } foreach (var entityType in entityTypes) { _entityByClassName.Add(entityType.Type.FullName, entityType.Type); if (!string.IsNullOrWhiteSpace(entityType.TypeShortAlias)) { _entityByTypeShortAlias.Add(entityType.TypeShortAlias, entityType.Type); } } }
/// <summary> /// /// </summary> /// <param name="builder"></param> /// <param name="typeFinder"></param> public void Register(ContainerBuilder builder, ITypeFinder typeFinder) { //注册Controller,实现属性注入 var IControllerType = typeof(ControllerBase); var arrControllerType = typeFinder.FindAll().Where(t => IControllerType.IsAssignableFrom(t) && t != IControllerType).ToArray(); builder.RegisterTypes(arrControllerType).PropertiesAutowired(); }
protected override Task <List <ModelDto> > FetchModelsAsync() { var types = _typeFinder.FindAll().Where(t => t.IsEntityType()) .Select(t => { var config = _entityConfigurationStore.Get(t); return(new ModelDto { ClassName = t.FullName, Type = t, Description = ReflectionHelper.GetDescription(t), Alias = config?.SafeTypeShortAlias }); }) .ToList(); return(Task.FromResult(types)); }
/// <summary> /// 获取所有实体类型 /// </summary> /// <param name="typeFinder"></param> /// <returns></returns> public static IEnumerable <Type> FindAllEntity(this ITypeFinder typeFinder) { return(typeFinder.FindAll().Where(e => e.BaseType == typeof(object) && e.GetCustomAttribute <TableAttribute>() != null)); }