public void PopulateFeature(IEnumerable <ApplicationPart> parts, ControllerFeature feature) { foreach (var dtoTupe in MapperUtils.GetAllDtos()) { var typeName = dtoTupe.Name + "Controller"; if (feature.Controllers.Any(t => t.Name == typeName)) { return; } var controllerType = typeof(ApiController <>).MakeGenericType(dtoTupe); feature.Controllers.Add(controllerType.GetTypeInfo()); } }
private void ResolveRelations() { var dtos = MapperUtils.GetAllDtos(); foreach (var dto in dtos) { var endpoint = dto.GetCustomAttributes().OfType <ApiEndpointAttribute>().FirstOrDefault(); if (endpoint is null) { continue; } var name = dto.BaseType.GetGenericArguments()[1].Name; //EntityTypeName _relations.Add(endpoint.Endpoint, new DtoRelation { RelationColumnName = $"{name}Id", DtoType = dto }); } }
public ApiBuilder AddDtoServices() { var dtos = MapperUtils.GetAllDtos(); foreach (var type in dtos) { var iServiceType = typeof(IService <>).MakeGenericType(type); if (Services.Any(t => t.ServiceType == iServiceType)) { continue; } var interfaces = type.GetInterfaces().Where(t2 => t2.IsGenericType && t2.GetGenericTypeDefinition() == typeof(IDto <,>)); foreach (var @interface in interfaces) { var genericArguments = @interface.GetGenericArguments(); var genericService = typeof(Service <,>).MakeGenericType(genericArguments[0], genericArguments[1]); Services.AddScoped(iServiceType, genericService); } } return(this); }
private void ResolveDtoProjections() { var dtos = MapperUtils.GetAllDtos(); foreach (var dto in dtos) { var projections = dto.GetInterfaces() .Select(t => new ProjectionDefinition { ProjectionType = t, Name = t.GetCustomAttribute <DtoProjectionAttribute>()?.ProjectionName, ProjectionProperties = t.GetProperties().Select(p => p.Name) }) .Where(t => t.Name != null); if (!projections.Any()) { continue; } DtoMetadata.Instance.Projections.Add(dto, projections); } }