1

I am looking at the source for the Project Silk project and there is a "handler" pattern that I have not seen before. First - this link from 2009 alludes to it but leaves me hanging

What the sample shows is a one method class where each class represents one method for each method in a related repository class. The classes are named like method names.

public class GetFillupsForVehicle
{
    private readonly IFillupRepository _fillupRepository;

    public GetFillupsForVehicle(IFillupRepository fillupRepository)
    {
        _fillupRepository = fillupRepository;
    }
    public virtual IEnumerable<FillupEntry> Execute(int vehicleId)
    {
        try
        {
            var fillups = _fillupRepository
                .GetFillups(vehicleId)
                .OrderBy(f => f.Date)
                .ToList();

            return new ReadOnlyCollection<FillupEntry>(fillups);
        }
        catch (InvalidOperationException ex)
        {
            throw new BusinessServicesException(Resources.UnableToRetireveFillupsExceptionMessage, ex);
        }
    }
}

Could someone explain this pattern or point me to something that I could read to learn more?

Thanks, Paul

Community
  • 1
  • 1
Paul Speranza
  • 2,302
  • 8
  • 26
  • 43
  • Then shouldn't the class be called GetFillupsForVehicleCommand? I need to dig into how this is called and now maybe it will make more sense. Thanks. – Paul Speranza Sep 27 '11 at 14:24
  • nothing says that a class must end with "Command" – jgauffin Sep 27 '11 at 14:47
  • But shouldn't class names be nouns? Anyway, I am looking at this sample app and - from the controllers - sometimes they call services (which call repositories) and sometimes they call these "commands" (which call repositories). I am trying to wrap my head around this whole pattern and I'm not sure how they decide which pattern to use. Thanks for your input. – Paul Speranza Sep 27 '11 at 15:09
  • Are you sure that they are sure about why they mix? ;) – jgauffin Sep 27 '11 at 15:47
  • It is the new Project Silk reference app from Microsoft Patterns & Practices. I'm not sure of anything at this point. – Paul Speranza Sep 27 '11 at 17:18
  • Feel like there is a subjective review you would like to have on this architecture http://bartekszafko.pl/2011/07/25/project-silk-subjective-review-part-3-ioc-a-problem-child/ – Siva Karthikeyan Aug 06 '12 at 07:01

1 Answers1

0

Please refer to this information about Project Silk which will be more relevant now to adopt.

In the code snippet which I have reposted from the PDF document provided by Microsoft on the Project Silk will help you understand how its being consumed. According to me its being considered more as scaffolding towards triggering the event at Business Domain level.

Also refer to this specific post which might be throwing light where they are heading to.

public ActionResult Add(int vehicleId)
{
var vehicles = Using<GetVehicleListForUser>()
.Execute(CurrentUserId);
var vehicle = vehicles.First(v => v.VehicleId == vehicleId);
var newFillupEntry = new FillupEntryFormModel
{
Odometer = (vehicle.Odometer.HasValue)
? vehicle.Odometer.Value : 0
};
var fillups = Using<GetFillupsForVehicle>()
.Execute(vehicleId)
.OrderByDescending(f => f.Date);
var viewModel = new FillupAddViewModel
{
VehicleList = new VehicleListViewModel(vehicles, vehicleId)
{IsCollapsed = true},
FillupEntry = newFillupEntry,
Fillups = new SelectedItemList<Model.FillupEntry>(fillups),
};
ViewBag.IsFirstFillup = (!fillups.Any());
return View(viewModel);
}

Siva Karthikeyan
  • 544
  • 8
  • 25
  • Kindly refer to this link http://weblogs.asp.net/shijuvarghese/archive/2011/10/18/cqrs-commands-command-handlers-and-command-dispatcher.aspx which will give you more insights on the handler and how its supposed to be handled in the flavor of CQRS – Siva Karthikeyan Aug 06 '12 at 07:02