Service Factory
Dynamic runtime generation of service classes from your Acumatica schema
Runtime Generation
Full Autocomplete
Type-Safe Methods
Architecture Overview
The Service Factory is the heart of Easy-Acumatica's dynamic architecture. Instead of maintaining static service definitions, it generates service classes at runtime by introspecting your Acumatica instance's OpenAPI and OData schemas.
Key Insight: Every service method is created dynamically when you initialize the client, ensuring perfect alignment with your instance's actual capabilities.
How It Works
- Schema Discovery: The client fetches OpenAPI and OData schemas from your instance
- Service Generation: ServiceFactory parses the schemas and creates service classes
- Method Creation: Each endpoint operation becomes a properly typed method
- Client Attachment: Services are attached to the client as attributes (e.g.,
client.bills
) - Stub Generation: Type stubs are created for IDE autocomplete support
Implementation Details
The Factory Process
The ServiceFactory
class performs sophisticated schema analysis:
class ServiceFactory:
"""Dynamically builds service classes from Acumatica schemas."""
def __init__(self, client: AcumaticaClient, schema: Dict[str, Any]):
self._client = client
self._schema = schema
def build_services(self) -> Dict[str, BaseService]:
"""Parse schemas and generate all services."""
services = {}
# Parse OpenAPI paths
paths = self._schema.get("paths", {})
for path, operations in paths.items():
tag = self._extract_tag(operations)
if tag not in services:
services[tag] = self._create_service(tag)
# Add methods for each operation
for method, details in operations.items():
self._add_method_to_service(
services[tag], path, method, details
)
# Parse OData metadata for Generic Inquiries
odata_services = self._parse_odata_metadata()
services.update(odata_services)
return services
The factory handles both OpenAPI paths (for standard REST operations) and OData metadata (for Generic Inquiries), creating a unified service interface.
Service Patterns
The Service Factory recognizes and implements these method patterns:
Method Pattern | Description |
---|---|
get_list(options) | Retrieves a filtered list of entities using OData query options |
get_by_id(entity_id, options) | Fetches a single entity by its primary key |
put_entity(data, options) | Creates a new entity or updates an existing one |
delete_by_id(entity_id) | Deletes an entity by its primary key |
invoke_action(invocation) | Executes a custom action on the entity |
put_file(entity_id, filename, data) | Attaches a file to an entity |
get_files(entity_id) | Retrieves files attached to an entity |
Naming Convention
Service names follow a predictable pattern:
- Entity Name:
Bill
→client.bills
- Multi-word:
SalesOrder
→client.sales_orders
- Inquiries:
AccountSummary
→client.account_summarys
Advanced Features
Best Practices
Let the Factory Work
Trust the automatic generation process. Services are created to match your exact instance configuration.
Generate Stubs for IDEs
Run the stub generator after client initialization for the best development experience.
Cache Schema Appropriately
Schema caching improves performance. Clear cache only when your instance structure changes.
Embrace Dynamic Methods
Methods are created to match your endpoints exactly. No need to worry about missing functionality.