-
-
Notifications
You must be signed in to change notification settings - Fork 0
Entity Registration
EntityAxis provides flexible, fluent APIs to register your entities and their services using dependency injection. This simplifies your setup, promotes consistency, and enables automatic handler and validator discovery.
Use AddEntityAxisCommandService to register a service that supports create, update, and delete operations:
services.AddEntityAxisCommandService<IProductCommandService, ProductService, Product, Guid>();This registers the following interfaces:
IProductCommandServiceICommandService<Product, Guid>ICreate<Product, Guid>IUpdate<Product, Guid>IDelete<Product, Guid>
💡 You should always register the generic interface
ICommandService<TEntity, TKey>explicitly. This ensures consistency and interoperability across libraries. If you're using the MediatR integration, it is required to resolve command handlers correctly.
Use AddEntityAxisQueryService to register a service that supports read operations:
services.AddEntityAxisQueryService<IProductQueryService, ProductService, Product, Guid>();This registers the following interfaces:
IProductQueryServiceIQueryService<Product, Guid>IGetById<Product, Guid>IGetAll<Product, Guid>IGetPaged<Product, Guid>
💡 Likewise,
IQueryService<TEntity, TKey>should be explicitly registered to support consistent resolution — and is necessary when using the MediatR implementation.
EntityAxis fully supports services that implement custom command and query contracts, allowing you to define rich, domain-specific interfaces without sacrificing the benefits of generic CRUD operations.
public interface IProductCommandService : ICommandService<Product, Guid>
{
Task DeactivateProductAsync(Guid id);
}As long as your custom interface inherits from the appropriate generic interface (ICommandService<TEntity, TKey> or IQueryService<TEntity, TKey>), EntityAxis will automatically detect and register it during service scanning.
💡 This approach gives you the best of both worlds: generic infrastructure for common operations and custom contracts for specialized business logic — all discoverable and injectable through a consistent registration model.
You can register all command and query services automatically by scanning assemblies:
services.AddEntityAxisCommandAndQueryServicesFromAssembly<ProductService>();Or scan multiple assemblies:
services.AddEntityAxisCommandAndQueryServicesFromAssemblies(new[]
{
typeof(ProductService).Assembly,
typeof(OtherService).Assembly
});EntityAxis will discover any class that implements ICommandService<,> or IQueryService<,> (even via a custom interface) and register all necessary interfaces for you.
- These registration methods typically belong in your Infrastructure layer.
- EntityAxis uses
TryAddto avoid overwriting existing service registrations. - Only generic interface types like
ICommandService<TEntity, TKey>are used internally by the library — ensure they're registered, even when using custom abstractions.