public static void MapControllersWithAttribute <T>(this IEndpointRouteBuilder endpoints) where T : Attribute { var dataSource = endpoints.GetEndpointDatasource(); if (dataSource != null) { var filteredEndpoints = dataSource.Endpoints.Where(e => e.Metadata.Any(m => m.GetType().Equals <T>())); var d = new DefaultEndpointDataSource(filteredEndpoints); endpoints.DataSources.Add(d); } }