diff --git a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs index aed05627..9a7e4de1 100644 --- a/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs +++ b/Octokit.Tests/Models/ReadOnlyPagedCollectionTests.cs @@ -27,7 +27,9 @@ namespace Octokit.Tests.Models }; var connection = Substitute.For(); connection.GetAsync>(nextPageUrl, null, null).Returns(nextPageResponse); - var pagedCollection = new ReadOnlyPagedCollection(response, connection); + var pagedCollection = new ReadOnlyPagedCollection( + response, + nextPageUri => connection.GetAsync>(nextPageUrl, null, null)); var nextPage = await pagedCollection.GetNextPage(); diff --git a/Octokit/Http/ApiConnection.cs b/Octokit/Http/ApiConnection.cs index b009d72c..44505790 100644 --- a/Octokit/Http/ApiConnection.cs +++ b/Octokit/Http/ApiConnection.cs @@ -241,7 +241,9 @@ namespace Octokit Ensure.ArgumentNotNull(uri, "uri"); var response = await Connection.GetAsync>(uri, parameters, accepts); - return new ReadOnlyPagedCollection(response, Connection); + return new ReadOnlyPagedCollection( + response, + nextPageUri => Connection.GetAsync>(nextPageUri, parameters, accepts)); } } } diff --git a/Octokit/Http/ReadOnlyPagedCollection.cs b/Octokit/Http/ReadOnlyPagedCollection.cs index 2dc1346d..f061388a 100644 --- a/Octokit/Http/ReadOnlyPagedCollection.cs +++ b/Octokit/Http/ReadOnlyPagedCollection.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Collections.ObjectModel; using System.Threading.Tasks; @@ -6,16 +7,16 @@ namespace Octokit.Internal { public class ReadOnlyPagedCollection : ReadOnlyCollection, IReadOnlyPagedCollection { - readonly IConnection _connection; readonly ApiInfo _info; + readonly Func>>> _nextPageFunc; - public ReadOnlyPagedCollection(IResponse> response, IConnection connection) + public ReadOnlyPagedCollection(IResponse> response, Func>>> nextPageFunc) : base(response != null ? response.BodyAsObject : null) { Ensure.ArgumentNotNull(response, "response"); - Ensure.ArgumentNotNull(connection, "connection"); + Ensure.ArgumentNotNull(nextPageFunc, "nextPageFunc"); - _connection = connection; + _nextPageFunc = nextPageFunc; _info = response.ApiInfo; } @@ -24,8 +25,8 @@ namespace Octokit.Internal var nextPageUrl = _info.GetNextPageUrl(); if (nextPageUrl == null) return null; - var response = await _connection.GetAsync>(nextPageUrl, null, null); - return new ReadOnlyPagedCollection(response, _connection); + var response = await _nextPageFunc(nextPageUrl); + return new ReadOnlyPagedCollection(response, _nextPageFunc); } } }