- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我将以Airbnb为例。
注册Airbnb帐户后,您可以通过创建列表来成为房东。要创建列表,Airbnb UI会分多个步骤指导您完成创建新列表的过程:
它还会记住您走过的最远的步骤,因此下一次要恢复该过程时,它将重定向到您离开的地方。
我一直在努力决定是否应该将 list 作为汇总根,并将方法定义为可用步骤,还是将每个步骤都视为自己的汇总根,以使其较小?
列为汇总根
public sealed class Listing : AggregateRoot
{
private List<Photo> _photos;
public Host Host { get; private set; }
public PropertyAddress PropertyAddress { get; private set; }
public Geolocation Geolocation { get; private set; }
public Pricing Pricing { get; private set; }
public IReadonlyList Photos => _photos.AsReadOnly();
public ListingStep LastStep { get; private set; }
public ListingStatus Status { get; private set; }
private Listing(Host host, PropertyAddress propertyAddress)
{
this.Host = host;
this.PropertyAddress = propertyAddress;
this.LastStep = ListingStep.GeolocationAdjustment;
this.Status = ListingStatus.Draft;
_photos = new List<Photo>();
}
public static Listing Create(Host host, PropertyAddress propertyAddress)
{
// validations
// ...
return new Listing(host, propertyAddress);
}
public void AdjustLocation(Geolocation newGeolocation)
{
// validations
// ...
if (this.Status != ListingStatus.Draft || this.LastStep < ListingStep.GeolocationAdjustment)
{
throw new InvalidOperationException();
}
this.Geolocation = newGeolocation;
}
...
}
聚合根中的大多数复杂类都是值对象,而
ListingStatus
只是一个简单的枚举:
public enum ListingStatus : int
{
Draft = 1,
Published = 2,
Unlisted = 3,
Deleted = 4
}
但是
ListingStep
可以是一个枚举类,用于存储当前步骤可以前进的下一步:
using Ardalis.SmartEnum;
public abstract class ListingStep : SmartEnum<ListingStep>
{
public static readonly ListingStep GeolocationAdjustment = new GeolocationAdjustmentStep();
public static readonly ListingStep Amenities = new AmenitiesStep();
...
private ListingStep(string name, int value) : base(name, value) { }
public abstract ListingStep Next();
private sealed class GeolocationAdjustmentStep : ListingStep
{
public GeolocationAdjustmentStep() :base("Geolocation Adjustment", 1) { }
public override ListingStep Next()
{
return ListingStep.Amenities;
}
}
private sealed class AmenitiesStep : ListingStep
{
public AmenitiesStep () :base("Amenities", 2) { }
public override ListingStep Next()
{
return ListingStep.Photos;
}
}
...
}
将所有内容都放在列表的总根中的好处是可以确保所有内容都具有事务一致性。步骤被定义为领域关注的问题之一。
public sealed class Listing : AggregateRoot
{
public Host Host { get; private set; }
public PropertyAddress PropertyAddress { get; private set; }
private Listing(Host host, PropertyAddress propertyAddress)
{
this.Host = host;
this.PropertyAddress = propertyAddress;
}
public static Listing Create(Host host, PropertyAddress propertyAddress)
{
// Validations
// ...
return new Listing(host, propertyAddress);
}
}
public sealed class ListingGeolocation : AggregateRoot
{
public Guid ListingId { get; private set; }
public Geolocation Geolocation { get; private set; }
private ListingGeolocation(Guid listingId, Geolocation geolocation)
{
this.ListingId = listingId;
this.Geolocation = geolocation;
}
public static ListingGeolocation Create(Guid listingId, Geolocation geolocation)
{
// Validations
// ...
return new ListingGeolocation(listingId, geolocation);
}
}
...
将每个步骤作为自己的聚合根的好处在于,它使聚合根变小(从某种程度上来说,我什至感觉它们太小了!),因此当将它们持久化回数据存储时,性能应该更快。
最佳答案
让我们讨论拆分大型集群聚合的两个原因:
Host
管理Listing
。其他用户只能发布评论。通过将Review
建模为单独的聚合,可以在根Listing
上实现事务一致性。 Listing
后,您通常会查询整个 list ,以便将其呈现给用户(除了可能是折叠的评论部分)。 ..., so next time when you want to resume the process, it will redirect to where you left.
ListingStep
,但是从域的角度来看真的有意义吗?是否需要在
Amenities
和
Description
之前指定
Title
?这真的是对
Listing
集合的关注吗,或者可以将其移至服务吗?当通过使用同一Service创建了所有
Listing
时,该Service可以轻松确定上次中断的位置。
Listing
作为聚合根似乎是一个不错的起点。
I thought about the wizard being the concept of the UI, rather than of the domain, because in theory, since each step doesn't depend on others, you can finish any step in any order.
I have no problem modeling those steps as their own aggregate roots, and have the UI determine where it left off last time.
My only concern of that approach is that, when all the steps are filled in and the listing is ready to be reviewed and published, who's responsible for it? I thought about the listing aggregate, but it doesn't have all the information.
ListingStatus
存储在
Listing
上,并使它后面的不变式成为根聚合的责任。这样,它应该具有所有信息,或者随其一起提供,以相应地更新
ListingStatus
。换句话说,这与向导步骤无关,而与描述聚合背后过程的名词和动词有关。在这种情况下,将输入保护所有数据的不变量,并且该变量当前处于要发布的正确状态。从那时起,仅以部分状态或不连贯的方式返回并保留聚合是非法的。
关于c# - 如何为将在多个步骤中创建的聚合建模,例如向导样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66098719/
我正在实现 WPF MVVM 向导,我想知道执行 DoOperation 的正确方法当加载新的向导页面 (UserControl) 时。 DoOperation在 MyWizard.ViewModal
我有一个场景,我正在尝试计划开始编码,并且我正在考虑使用django向导。 我的计划是通过两个步骤构建一个 django 向导,第一个简单,但第二个有点复杂。第二步将包含一个表单,该表单将根据第一步选
我想看看这些是否“建立了……” Flash网站(以支持用户定制的订购过程)是使用常规Flash还是Flex完成的? Site 1 Site 2 Site 3 Site 4 所有这些都可以通过定制的订购
我在人们提交一些数据的表单上使用了 FuelUX 向导,我们希望将其分解为逻辑步骤。效果非常好。 现在我正在处理相同表单的编辑版本,它工作正常,但由于步骤已经加载了数据,我希望用户能够直接跳到步骤 X
我有一个足够大的模型,可以切割成 3 种形式。我想使用 FormWizzard 来做到这一点,但我想知道,如何将表单中的信息保存到数据库? 所有东西都来自同一个模型。 你知道如何做到这一点吗? 最佳答
我使用 Primefaces 3.5。并尝试在的onnext处理程序中调用js函数。我希望在当前选项卡验证结果后,onnext 返回特定选项卡上的选项卡。我的验证函数 function val
我在我的应用程序中实现了向导 Bootstrap 。 我想检索当前选项卡的索引来测试显示或隐藏按钮“下一个”“上一个” $('#rootwizard').bootstrapWizard({ '
我想创建一个基于终端的安装程序/向导。 理想情况下,它就像 Ubuntu 服务器安装程序或 Arch Linux 安装程序——一个 ncurses (?) 重的 GUI,具有很多形式和箭头键优点。 其
问题 我的 WizardPage 中有一个 Composite,如果该 Composite 比向导窗口大,我想向其中添加滚动条,但到目前为止我尝试过的方法都不起作用。有人知道如何添加滚动条吗? 我想将
我正在尝试制作一个引导步骤表单,但它不想工作。我正在使用这段代码: https://codepen.io/digitalavinash/pen/VjyAXx?fbclid=IwAR2j8hRIG0gn
我目前正在开发一个网站(与健身相关),客户想要做一个功能,允许用户根据您从类似于 this example 上的 slider 中选择的选项来选择锻炼计划。 . 我想知道这是否可以用 CSS 完成,或
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 6 年前。 Improve
这应该很简单,但我错过了。我试图通过在我的 stylesheet.css 中使用此 css 将文本居中放置在我的向导 h1 标签中 .h1textalign { text-align:center;
我已经在这里问过这个问题 Creating next and back button on tabs bootstrap 3 wizard? 但我现在已经扩展它以在最后一个选项卡上添加完成,但现在我在
摩尔庄园手游已经上线好几天了,身边不少小伙伴也都开始玩了,不过其中的还是有不少的玩法等待大家去解锁,比如大家知道怎么去传送好友,蘑菇吗?向导怎么传送呢?有哪些方法和技巧?下面就和小编一起来看看。
每次我在我的 Android Studio 中为该项目创建一个新 fragment 时,它都会创建 android.support.v4.app.Fragment ,这不是我想要的。此外,它总是会触发
我正在为我的公司项目使用 SAPUI5 向导,但由于某种原因它对我不起作用。 这是我的代码: var allSteps = oWizardElement.getSteps(); var stepOne
在扩展中,我希望能够修改现有链接。数据库中的相应字段可能包含多个链接(例如 tt_content.bodytext)。 我想尽可能多地重用现有的功能。所以我想使用已经存在的链接向导。 我找到的是现有路
长话短说,我有一个开发人员让我成为一名向导,即使我付了钱给他,他也没有在没有回复的情况下离开,并坚持使用一个半工作的Python向导。 该向导在 Kodi 内部运行,下载并解压 zip 文件。但有时我
我对 Fuel UX 向导有疑问。当我按下 fuel ux 向导上的下一步按钮时,我发送使用 validate_step(step) 选择的 category_id 并使用来自 php 的 json
我是一名优秀的程序员,十分优秀!