Entity configuration
The following configuration options are available for customizing the behavior of your entities in the Slothful CRUD library:
- AllowAnonymous: Disables authorization checks for the entity.
- RequireAuthorization: Enables authorization checks and applies the specified policies.
- SetSortProperty: Sets the property used for sorting entities.
- SetFilterProperty: Sets the property used for filtering entities.
- SetKeyProperty: Sets the key property and also sets the key property type.
- SetKeyPropertyType: Sets the type of the key property.
- SetUpdateMethodName: Sets the method name used to update entities.
- ExposeAllNestedProperties: Exposes all nested properties.
Calling SetKeyProperty also invokes SetKeyPropertyType to ensure consistency.
How configuration is discovered
Entity configurations are discovered automatically from the assembly marker when UseSlothfulCrud<TDbContext, TAssemblyMarker>() is executed.
The following rules apply:
- Configuration classes must implement
ISlothEntityConfiguration<TEntity>. - Configuration classes must have a public parameterless constructor.
- Only one configuration can be registered per entity type. Registering another one for the same entity results in a configuration exception.
- If no configuration is found for an entity, default configuration values are used.
Example Usage
Below is an example configuration using default values:
public class SlothConfiguration : ISlothEntityConfiguration<Sloth>
{
public void Configure(SlothEntityBuilder<Sloth> builder)
{
builder
.ExposeAllNestedProperties(false) // Default value
.SetSortProperty(x => x.Name) // Default value
.SetFilterProperty(x => x.Name) // Default value
.SetUpdateMethodName("Update") // Default value
.SetKeyProperty(x => x.Id) // Default value
.SetKeyPropertyType(x => x.Id) // Default value
.HasValidation(); // Default value
}
}
These settings illustrate the use of default values for the entity configuration in Slothful CRUD. This is equivalent to:
public class SlothConfiguration : ISlothEntityConfiguration<Sloth>
{
public void Configure(SlothEntityBuilder<Sloth> builder)
{
}
}