@@ -45,6 +45,12 @@ public abstract class ModelBuilder<TModel> : IBuilder<TModel>, IRecreatable<Mode
45
45
/// </summary>
46
46
protected readonly IBuilderFactory _factory ;
47
47
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
+
48
54
/// <summary>
49
55
/// ModelBuilder that uses the same Persistor to Persist itself as it's children
50
56
/// Used by the common builders, that just build a model
@@ -64,8 +70,10 @@ public TModel Build()
64
70
{
65
71
_factory . PreBuild . Execute < TModel > ( this ) ;
66
72
_model = BuildModel ( ) ;
67
- AfterModel ( _model ) ;
73
+
74
+ if ( _prePipelinePostBuild ) PostBuild ( _model ) ;
68
75
_factory . PostBuild . Execute < TModel > ( _model ! ) ;
76
+ if ( ! _prePipelinePostBuild ) PostBuild ( _model ) ;
69
77
}
70
78
return _model ;
71
79
}
@@ -78,7 +86,6 @@ public TModel Build()
78
86
79
87
/// <summary>
80
88
/// 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.
82
89
/// This allows us to resolve a dependency of a child builder, without running into a cyclic call.
83
90
///
84
91
/// The way this works is, the parent will get build, without the children connected,
@@ -87,8 +94,11 @@ public TModel Build()
87
94
/// model = Parent.Build();
88
95
/// child = _childBuilder.WithParent(Parent).Build();
89
96
/// 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.
90
100
/// </summary>
91
- protected virtual void AfterModel ( TModel model )
101
+ protected virtual void PostBuild ( TModel model )
92
102
{
93
103
// intentionally empty, since this is a optional action, to be overwritten by specific builders
94
104
}
0 commit comments