Project Silk 中的处理程序模式

发布于 2024-12-07 02:14:44 字数 1040 浏览 2 评论 0原文

我正在查看 Project Silk 项目的源代码,发现有一个我以前从未见过的“处理程序”模式。首先 - 这个 2009 年的链接暗示了它,但让我悬而未决。

示例显示的是一个单一方法类,其中每个class 代表相关存储库类中每个方法的一个方法。类的命名类似于方法名称。

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

有人可以解释一下这种模式或向我指出一些我可以阅读以了解更多信息的内容吗?

谢谢, 保罗

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

奢华的一滴泪 2024-12-14 02:14:44

请参阅有关 Project Silk 的信息,该信息现在与采纳。

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

另请参阅此特定帖子,它可能会阐明他们要去的地方。

<代码>

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

<代码>

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文