Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Removed yet a dependency on Func<IViewRepository>.

AFACT, this was the last dependency on this particular factory.

All in all, I think this refactoring removed more lines of code than it
added, and it also reduced the cyclomatic complexity of the code.

All tests are still green.
  • Loading branch information...
commit 375aefdc65336cabe845faf70fdf39beefe47ea6 1 parent 7b91213
@ploeh authored
View
2  source/Conference/Conference.Web.Public.Tests/Controllers/RegistrationControllerFixture.cs
@@ -36,7 +36,7 @@ public given_controller()
this.bus = Mock.Of<ICommandBus>();
this.viewRepository = Mock.Of<IViewRepository>();
- this.sut = new RegistrationController(this.bus, () => this.viewRepository);
+ this.sut = new RegistrationController(this.bus, this.viewRepository);
}
[Fact]
View
57 source/Conference/Conference.Web.Public/Controllers/RegistrationController.cs
@@ -27,17 +27,17 @@ public class RegistrationController : Controller
private const int WaitTimeoutInSeconds = 5;
private ICommandBus commandBus;
- private Func<IViewRepository> repositoryFactory;
+ private readonly IViewRepository repository;
public RegistrationController()
- : this(MvcApplication.GetService<ICommandBus>(), MvcApplication.GetService<Func<IViewRepository>>())
+ : this(MvcApplication.GetService<ICommandBus>(), MvcApplication.GetService<IViewRepository>())
{
}
- public RegistrationController(ICommandBus commandBus, Func<IViewRepository> repositoryFactory)
+ public RegistrationController(ICommandBus commandBus, IViewRepository repository)
{
this.commandBus = commandBus;
- this.repositoryFactory = repositoryFactory;
+ this.repository = repository;
}
[HttpGet]
@@ -84,14 +84,10 @@ public ActionResult StartRegistration(string conferenceCode, OrderViewModel cont
[HttpGet]
public ActionResult SpecifyPaymentDetails(string conferenceCode, Guid orderId)
{
- var repo = this.repositoryFactory();
- using (repo as IDisposable)
- {
- var orderDTO = repo.Find<OrderDTO>(orderId);
- var viewModel = this.CreateViewModel(conferenceCode, orderDTO);
+ var orderDTO = this.repository.Find<OrderDTO>(orderId);
+ var viewModel = this.CreateViewModel(conferenceCode, orderDTO);
- return View(viewModel);
- }
+ return View(viewModel);
}
[HttpPost]
@@ -121,25 +117,20 @@ public ActionResult ThankYou(string conferenceCode, Guid orderId)
private OrderViewModel CreateViewModel(string conferenceCode)
{
- var repo = this.repositoryFactory();
+ var conference = this.repository.Query<ConferenceDTO>().FirstOrDefault(c => c.Code == conferenceCode);
- using (repo as IDisposable)
- {
- var conference = repo.Query<ConferenceDTO>().FirstOrDefault(c => c.Code == conferenceCode);
-
- //// TODO check null case
+ //// TODO check null case
- var viewModel =
- new OrderViewModel
- {
- ConferenceId = conference.Id,
- ConferenceCode = conference.Code,
- ConferenceName = conference.Name,
- Items = conference.Seats.Select(s => new OrderItemViewModel { SeatTypeId = s.Id, SeatTypeDescription = s.Description, Price = s.Price }).ToList()
- };
+ var viewModel =
+ new OrderViewModel
+ {
+ ConferenceId = conference.Id,
+ ConferenceCode = conference.Code,
+ ConferenceName = conference.Name,
+ Items = conference.Seats.Select(s => new OrderItemViewModel { SeatTypeId = s.Id, SeatTypeDescription = s.Description, Price = s.Price }).ToList()
+ };
- return viewModel;
- }
+ return viewModel;
}
private OrderViewModel CreateViewModel(string conferenceCode, OrderDTO orderDTO)
@@ -180,15 +171,11 @@ private OrderDTO WaitUntilUpdated(Guid orderId)
while (DateTime.Now < deadline)
{
- var repo = this.repositoryFactory();
- using (repo as IDisposable)
- {
- var orderDTO = repo.Find<OrderDTO>(orderId);
+ var orderDTO = this.repository.Find<OrderDTO>(orderId);
- if (orderDTO != null && orderDTO.State != "Created")
- {
- return orderDTO;
- }
+ if (orderDTO != null && orderDTO.State != "Created")
+ {
+ return orderDTO;
}
Thread.Sleep(500);
Please sign in to comment.
Something went wrong with that request. Please try again.