Class ModelHandlerBuilder<T, TKey>
- Namespace
- Htmx.Components.Models.Builders
- Assembly
- Htmx.Components.dll
Provides a fluent API for configuring and building model handlers that manage CRUD operations and UI generation. This builder configures data access, business logic delegates, table presentation, and input models for a specific entity type.
public class ModelHandlerBuilder<T, TKey> : BuilderBase<ModelHandlerBuilder<T, TKey>, ModelHandler<T, TKey>> where T : class, new()
Type Parameters
T
The model type being handled, must be a reference type with a parameterless constructor
TKey
The type of the model's primary key
- Inheritance
-
ModelHandlerBuilder<T, TKey>
- Inherited Members
- Extension Methods
Methods
BuildImpl()
Builds the configured model handler instance. This method is called internally by the builder framework to create the final model handler.
protected override Task<ModelHandler<T, TKey>> BuildImpl()
Returns
- Task<ModelHandler<T, TKey>>
A task that represents the asynchronous build operation. The task result contains the configured model handler.
WithCreate(Func<T, Task<Result<T>>>)
Configures the create operation for adding new entities. This enables create CRUD functionality and sets up the associated action models for UI generation. Also registers the create operation with the authorization system.
public ModelHandlerBuilder<T, TKey> WithCreate(Func<T, Task<Result<T>>> createModel)
Parameters
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithDelete(Func<TKey, Task<Result>>)
Configures the delete operation for removing entities. This enables delete CRUD functionality and sets up the associated action models for UI generation. Also registers the delete operation with the authorization system.
public ModelHandlerBuilder<T, TKey> WithDelete(Func<TKey, Task<Result>> deleteModel)
Parameters
deleteModel
Func<TKey, Task<Result>>A function that deletes an entity by its key and returns the result
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithInput<TProp>(Expression<Func<T, TProp>>, Action<InputModelBuilder<T, TProp>>)
Configures an input model for a specific property of the entity. Input models define how properties are edited in forms, including validation, UI controls, and behavior.
public ModelHandlerBuilder<T, TKey> WithInput<TProp>(Expression<Func<T, TProp>> propertySelector, Action<InputModelBuilder<T, TProp>> configure)
Parameters
propertySelector
Expression<Func<T, TProp>>An expression that selects the property to configure
configure
Action<InputModelBuilder<T, TProp>>An action that configures the input model builder for the property
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
Type Parameters
TProp
The type of the property being configured
WithKeySelector(Expression<Func<T, TKey>>)
Configures the key selector expression that identifies the primary key property or properties of the model. This expression is used for entity identification, filtering, and CRUD operations.
public ModelHandlerBuilder<T, TKey> WithKeySelector(Expression<Func<T, TKey>> keySelector)
Parameters
keySelector
Expression<Func<T, TKey>>An expression that selects the primary key from the model
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithQueryable(Func<IQueryable<T>>)
Configures the queryable data source for read operations. This delegate provides the base query for retrieving entities and enables read CRUD functionality. Also registers the read operation with the authorization system.
public ModelHandlerBuilder<T, TKey> WithQueryable(Func<IQueryable<T>> getQueryable)
Parameters
getQueryable
Func<IQueryable<T>>A function that returns the queryable data source for the model
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithTable(Action<TableModelBuilder<T, TKey>>)
Configures the table model builder that defines how the entities are displayed in tabular format. This allows customization of columns, actions, filtering, and other table-specific settings.
public ModelHandlerBuilder<T, TKey> WithTable(Action<TableModelBuilder<T, TKey>> configure)
Parameters
configure
Action<TableModelBuilder<T, TKey>>An action that configures the table model builder
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithTypeId(string)
Sets the unique type identifier for this model handler. This identifier is used for routing, authorization, and UI component registration.
public ModelHandlerBuilder<T, TKey> WithTypeId(string typeId)
Parameters
typeId
stringA unique string identifier for the model type
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining
WithUpdate(Func<T, Task<Result<T>>>)
Configures the update operation for modifying existing entities. This enables update CRUD functionality and sets up the associated action models for UI generation. Also registers the update operation with the authorization system.
public ModelHandlerBuilder<T, TKey> WithUpdate(Func<T, Task<Result<T>>> updateModel)
Parameters
updateModel
Func<T, Task<Result<T>>>A function that updates an existing entity and returns the result
Returns
- ModelHandlerBuilder<T, TKey>
The current builder instance for method chaining