Skip to content

Commit

Permalink
[Strategies] Remove IDependencyContainer parameter from location meth…
Browse files Browse the repository at this point in the history
…od as frequently unused and can be provided in constructor.
  • Loading branch information
Aleksbgbg committed Jun 20, 2019
1 parent 33bbf53 commit 199107e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 8 deletions.
11 changes: 9 additions & 2 deletions Wingman.Tests/Container/Strategies/HandlerStrategyTests.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace Wingman.Tests.Container.Strategies
{
using System;

using Moq;

using Wingman.Container;
Expand All @@ -21,7 +23,7 @@ public void TestReturnsHandlerResult()
{
object expectedObject = new object();

object actualObject = new HandlerStrategy(_ => expectedObject).LocateService(null);
object actualObject = HandlerStrategy(_ => expectedObject).LocateService();

Assert.Same(expectedObject, actualObject);
}
Expand All @@ -31,9 +33,14 @@ public void TestPassesDependencyRetrieverArgument()
{
IDependencyRetriever actualRetriever = null;

new HandlerStrategy(passedInRetriever => actualRetriever = passedInRetriever).LocateService(_dependencyRetrieverMock.Object);
HandlerStrategy(passedInRetriever => actualRetriever = passedInRetriever).LocateService();

Assert.Same(_dependencyRetrieverMock.Object, actualRetriever);
}

private HandlerStrategy HandlerStrategy(Func<IDependencyRetriever, object> handler)
{
return new HandlerStrategy(_dependencyRetrieverMock.Object, handler);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public void TestReturnsImplementation()
object expectedService = new object();
InstanceStrategy strategy = new InstanceStrategy(expectedService);

object actualService = strategy.LocateService(null);
object actualService = strategy.LocateService();

Assert.Equal(expectedService, actualService);
}
Expand Down
9 changes: 6 additions & 3 deletions Wingman/Container/Strategies/HandlerStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

public class HandlerStrategy : IServiceLocationStrategy
{
private readonly IDependencyRetriever _dependencyRetriever;

private readonly Func<IDependencyRetriever, object> _handler;

public HandlerStrategy(Func<IDependencyRetriever, object> handler)
public HandlerStrategy(IDependencyRetriever dependencyRetriever, Func<IDependencyRetriever, object> handler)
{
_dependencyRetriever = dependencyRetriever;
_handler = handler;
}

public object LocateService(IDependencyRetriever dependencyRetriever)
public object LocateService()
{
return _handler(dependencyRetriever);
return _handler(_dependencyRetriever);
}
}
}
2 changes: 1 addition & 1 deletion Wingman/Container/Strategies/IServiceLocationStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
{
internal interface IServiceLocationStrategy
{
object LocateService(IDependencyRetriever dependencyRetriever);
object LocateService();
}
}
2 changes: 1 addition & 1 deletion Wingman/Container/Strategies/InstanceStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public InstanceStrategy(object implementation)
_implementation = implementation;
}

public object LocateService(IDependencyRetriever dependencyRetriever)
public object LocateService()
{
return _implementation;
}
Expand Down

0 comments on commit 199107e

Please sign in to comment.