Class EditScreenModelExtensionInjector<TScreen, TModel, TExtensionModel>
- Namespace
- Dynamicweb.CoreUI.Screens
- Assembly
- Dynamicweb.CoreUI.dll
Base class for adding a 3rd-party extension's own fields to an EditScreenBase<TModel>, without
modifying TModel itself and without the extra fields ending up in a dictionary.
Implementations are discovered automatically via AddInManager - no DI registration required.
public abstract class EditScreenModelExtensionInjector<TScreen, TModel, TExtensionModel> : EditScreenInjector<TScreen, TModel> where TScreen : EditScreenBase<TModel>, new() where TModel : DataViewModelBase, IIdentifiable, new() where TExtensionModel : class, new()
Type Parameters
TScreenThe edit screen type to inject into.
TModelThe data model type used by the screen.
TExtensionModelA plain data class holding the extension's own fields.
- Inheritance
-
ScreenInjector<TScreen>EditScreenInjector<TScreen, TModel>EditScreenModelExtensionInjector<TScreen, TModel, TExtensionModel>
- Inherited Members
Remarks
Pair this injector with a matching IModelExtensionCommandHandler<TModel, TExtensionModel>,
which persists TExtensionModel once the screen's save command has run. Any number of
extensions - each with its own TExtensionModel - can target the same screen; they never
need to coordinate with each other, because every editor this class adds is automatically namespaced by
TExtensionModel's own type name, so two extensions can freely reuse the same property
names without colliding on the wire.
Example:
public sealed class LoyaltyProfileExtension
{
public int Points { get; set; }
public string? Tier { get; set; }
}
public sealed class LoyaltyProfileEditScreenInjector : EditScreenModelExtensionInjector<UserEditScreen, UserDataModel, LoyaltyProfileExtension>
{
public override void BuildEditors(EditScreenBase<UserDataModel>.EditScreenBuilder builder, LoyaltyProfileExtension extension)
{
builder.AddComponents("General", "Loyalty", new UiComponentBase[]
{
new Number { Name = WireName(nameof(LoyaltyProfileExtension.Points)), Label = "Points", Value = extension.Points },
new Text { Name = WireName(nameof(LoyaltyProfileExtension.Tier)), Label = "Tier", Value = extension.Tier },
});
}
}
The corresponding IModelExtensionCommandHandler<TModel, TExtensionModel> implements
Load the same way BuildEditors(EditScreenBuilder, TExtensionModel) obtains its current value from - both must agree on where
the extension's data actually lives, since the injector and the handler are discovered and invoked independently.
Methods
BuildEditors(EditScreenBuilder, TExtensionModel)
Adds editors for extension's fields to the screen. Give each editor a Name of
WireName(string) so its value round-trips back to the matching
IModelExtensionCommandHandler<TModel, TExtensionModel> on save.
protected abstract void BuildEditors(EditScreenBase<TModel>.EditScreenBuilder builder, TExtensionModel extension)
Parameters
builderEditScreenBase<TModel>.EditScreenBuilderextensionTExtensionModel
Load(TModel)
Loads the extension's current persisted value for model. Return a new, empty
TExtensionModel when the extension has no data yet (e.g. a new record).
protected abstract TExtensionModel Load(TModel model)
Parameters
modelTModel
Returns
- TExtensionModel
OnBuildEditScreen(EditScreenBuilder)
Override to add or modify groups and editors on the screen.
Called after the screen's own BuildEditScreen method completes.
public override sealed void OnBuildEditScreen(EditScreenBase<TModel>.EditScreenBuilder builder)
Parameters
builderEditScreenBase<TModel>.EditScreenBuilderBuilder for the target screen; use
AddComponentsandEditorFor.
WireName(string)
Builds the wire-safe, collision-free name for an editor bound to TExtensionModel's
propertyName property. Use with nameof(...), e.g.
WireName(nameof(LoyaltyProfileExtension.Points)).
protected static string WireName(string propertyName)
Parameters
propertyNamestring