Skip to content

Commit 6b63859

Browse files
author
Raphael Hoppe
committed
Option for running PostBuild pre or post pipeline
1 parent 41b1d4b commit 6b63859

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

Diff for: Directory.Build.props

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<Company>queo GmbH</Company>
66
<Copyright>2023 queo GmbH</Copyright>
77
<Product>Queo Commons ModelBuilder Library</Product>
8-
<AssemblyVersion>0.1.1</AssemblyVersion>
8+
<AssemblyVersion>0.1.2</AssemblyVersion>
99
<FileVersion>$(AssemblyVersion)</FileVersion>
1010
<version>$(AssemblyVersion)-Beta</version>
1111
</PropertyGroup>

Diff for: src/Commons.Builders.Model/Builder/ModelBuilder.cs

+13-3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ public abstract class ModelBuilder<TModel> : IBuilder<TModel>, IRecreatable<Mode
4545
/// </summary>
4646
protected readonly IBuilderFactory _factory;
4747

48+
/// <summary>
49+
/// Flag that specifies if the post build should be run before or after the pipeline.
50+
/// The pipeline is provided by the factory and will usually contain the persist post build action.
51+
/// </summary>
52+
protected bool _prePipelinePostBuild = false;
53+
4854
/// <summary>
4955
/// ModelBuilder that uses the same Persistor to Persist itself as it's children
5056
/// Used by the common builders, that just build a model
@@ -64,8 +70,10 @@ public TModel Build()
6470
{
6571
_factory.PreBuild.Execute<TModel>(this);
6672
_model = BuildModel();
67-
AfterModel(_model);
73+
74+
if (_prePipelinePostBuild) PostBuild(_model);
6875
_factory.PostBuild.Execute<TModel>(_model!);
76+
if (!_prePipelinePostBuild) PostBuild(_model);
6977
}
7078
return _model;
7179
}
@@ -78,7 +86,6 @@ public TModel Build()
7886

7987
/// <summary>
8088
/// Method that can be overwritten for common 'Chicken and egg' situations during setup
81-
/// This will run before the factories post actions are executed, but after the model is build.
8289
/// This allows us to resolve a dependency of a child builder, without running into a cyclic call.
8390
///
8491
/// The way this works is, the parent will get build, without the children connected,
@@ -87,8 +94,11 @@ public TModel Build()
8794
/// model = Parent.Build();
8895
/// child = _childBuilder.WithParent(Parent).Build();
8996
/// model.Add(child);
97+
///
98+
/// If this post build should be run before the pipeline actions (factory.PostBuild)
99+
/// the _prePipelinePostBuild flag can be set to true.
90100
/// </summary>
91-
protected virtual void AfterModel(TModel model)
101+
protected virtual void PostBuild(TModel model)
92102
{
93103
// intentionally empty, since this is a optional action, to be overwritten by specific builders
94104
}

Diff for: tests/Examples/Relations/CountryBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public CountryBuilder WithPresident(Action<PresidentBuilder> buildAction) => Set
2727

2828
protected override Country BuildModel() => new(_name);
2929

30-
protected override void AfterModel(Country model)
30+
protected override void PostBuild(Country model)
3131
{
3232
if (_president is not null)
3333
{

Diff for: tests/Examples/Relations/UserBuilder.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public UserBuilder WithOrg(Action<OrgBuilder> buildAction) => Set(() =>
2626

2727
protected override User BuildModel() => new(_name);
2828

29-
protected override void AfterModel(User model)
29+
protected override void PostBuild(User model)
3030
{
3131
if (_org is not null)
3232
{

0 commit comments

Comments
 (0)