-
-
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 supports services that implement custom interfaces like this:
public interface IProductCommandService : ICommandService<Product, Guid> { }As long as your custom interface inherits from the generic interface (ICommandService<TEntity, TKey> or IQueryService<TEntity, TKey>), it will be properly discovered and registered.
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.