项目丝绸中的处理程序模式

时间:2011-09-27 14:05:22

标签: design-patterns repository handler

我正在查看Project Silk项目的源代码,并且有一个我以前没见过的“处理程序”模式。首先 - 来自2009年的这个link暗示了它,但让我不知所措。

示例显示的是一个方法类,其中每个类表示相关存储库类中每个方法的一个方法。这些类被命名为方法名称。

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);
        }
    }
}

有人可以解释这种模式,还是指出一些我可以阅读以了解更多信息的内容?

谢谢, 保罗

1 个答案:

答案 0 :(得分:0)

请参阅有关Project Silk的信息,这些信息现在将更具相关性。

在我从Project Silk提供的PDF文档中重新发布的代码片段中,可以帮助您了解它的使用方式。据我所知,它被视为在业务领域级别触发事件的脚手架。

另请参阅此specific post,它可能会在他们前往的地方投光。

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);
}

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); }