better DI
This commit is contained in:
parent
299ad64269
commit
2e8313301b
4 changed files with 19 additions and 17 deletions
|
@ -17,12 +17,12 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
public class RetrieveTweetsProcessor : IRetrieveTweetsProcessor
|
||||
{
|
||||
private readonly ITwitterTweetsService _twitterTweetsService;
|
||||
private readonly ITwitterUserService _twitterUserService;
|
||||
private readonly ICachedTwitterUserService _twitterUserService;
|
||||
private readonly ITwitterUserDal _twitterUserDal;
|
||||
private readonly ILogger<RetrieveTweetsProcessor> _logger;
|
||||
|
||||
#region Ctor
|
||||
public RetrieveTweetsProcessor(ITwitterTweetsService twitterTweetsService, ITwitterUserDal twitterUserDal, ITwitterUserService twitterUserService, ILogger<RetrieveTweetsProcessor> logger)
|
||||
public RetrieveTweetsProcessor(ITwitterTweetsService twitterTweetsService, ITwitterUserDal twitterUserDal, ICachedTwitterUserService twitterUserService, ILogger<RetrieveTweetsProcessor> logger)
|
||||
{
|
||||
_twitterTweetsService = twitterTweetsService;
|
||||
_twitterUserDal = twitterUserDal;
|
||||
|
@ -77,13 +77,8 @@ namespace BirdsiteLive.Pipeline.Processors
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_logger.LogError(e, "Error retrieving TL of {Username} from {LastTweetPostedId}", user.Acct, user.LastTweetPostedId);
|
||||
|
||||
if (_twitterUserService is CachedTwitterUserService service)
|
||||
{
|
||||
_logger.LogInformation("Purge {Username} from cache", user.Acct);
|
||||
service.PurgeUser(user.Acct);
|
||||
}
|
||||
_logger.LogError(e, "Error retrieving TL of {Username} from {LastTweetPostedId}, purging user from cache", user.Acct, user.LastTweetPostedId);
|
||||
_twitterUserService.PurgeUser(user.Acct);
|
||||
}
|
||||
|
||||
return tweets;
|
||||
|
|
|
@ -4,7 +4,12 @@ using Microsoft.Extensions.Caching.Memory;
|
|||
|
||||
namespace BirdsiteLive.Twitter
|
||||
{
|
||||
public class CachedTwitterUserService : ITwitterUserService
|
||||
public interface ICachedTwitterUserService : ITwitterUserService
|
||||
{
|
||||
void PurgeUser(string username);
|
||||
}
|
||||
|
||||
public class CachedTwitterUserService : ICachedTwitterUserService
|
||||
{
|
||||
private readonly ITwitterUserService _twitterService;
|
||||
|
||||
|
|
|
@ -14,12 +14,14 @@
|
|||
<PackageReference Include="coverlet.collector" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BirdsiteLive.Pipeline\BirdsiteLive.Pipeline.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Tools\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\BirdsiteLive.Pipeline\BirdsiteLive.Pipeline.csproj" />
|
||||
<ProjectReference Include="..\..\BirdsiteLive.Twitter\BirdsiteLive.Twitter.csproj" />
|
||||
<ProjectReference Include="..\..\DataAccessLayers\BirdsiteLive.DAL\BirdsiteLive.DAL.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
@ -61,7 +61,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
))
|
||||
.Returns(Task.CompletedTask);
|
||||
|
||||
var twitterUserServiceMock = new Mock<ITwitterUserService>(MockBehavior.Strict);
|
||||
var twitterUserServiceMock = new Mock<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
|
||||
var logger = new Mock<ILogger<RetrieveTweetsProcessor>>(MockBehavior.Strict);
|
||||
#endregion
|
||||
|
@ -125,7 +125,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
|
||||
var twitterUserServiceMock = new Mock<ITwitterUserService>(MockBehavior.Strict);
|
||||
var twitterUserServiceMock = new Mock<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
|
||||
var logger = new Mock<ILogger<RetrieveTweetsProcessor>>(MockBehavior.Strict);
|
||||
#endregion
|
||||
|
@ -192,7 +192,7 @@ namespace BirdsiteLive.Pipeline.Tests.Processors
|
|||
|
||||
var twitterUserDalMock = new Mock<ITwitterUserDal>(MockBehavior.Strict);
|
||||
|
||||
var twitterUserServiceMock = new Mock<ITwitterUserService>(MockBehavior.Strict);
|
||||
var twitterUserServiceMock = new Mock<ICachedTwitterUserService>(MockBehavior.Strict);
|
||||
|
||||
var logger = new Mock<ILogger<RetrieveTweetsProcessor>>(MockBehavior.Strict);
|
||||
#endregion
|
||||
|
|
Reference in a new issue