DEV Community

Peter + AI
Peter + AI

Posted on

Understanding Entity Services in Uniface 10.4 πŸš€

This blog post was created with the help of AI πŸ€–. I tried to keep the language as simple and clear as possible, so that even developers who are new to Uniface can follow along.

What are Entity Services? πŸ“¦

In Uniface 10.4, Entity Services are special components that manage business rules and database access for a single entity (like a table). Instead of letting the user interface (UI) directly talk to the database, the Entity Service sits in between.

This design helps keep the presentation logic (what the user sees) separate from the business logic (how data is processed). It is often needed in larger, distributed applications where data access must be centralized.

Why should you use them? πŸ€”

  • They simplify and standardize database access.
  • They allow multiple components to use the same entity logic.
  • They hide complexity away from the visible UI parts.

How do Entity Services work? βš™οΈ

An Entity Service can be implicitly or explicitly activated:

  • Implicit: If a component has its data access set to an entity service, Uniface automatically creates an instance of that service when the component runs. It is removed when the component ends.
  • Explicit: Developers can also create an Entity Service with the newinstance and activate commands. In this case, it must also be explicitly deleted with deleteinstance.

Example πŸ“

Let’s say we have an entity called Customer. Instead of letting each UI form access the database directly, we create an Entity Service: CustomerESV. All forms use this service for reading and saving data.

This way, if the database rules change (for example, a new field is required), we only update the logic in CustomerESV, and every form that uses it stays consistent. πŸŽ‰

Important Note ⚠️

In Uniface, if you use an entity and its functional subtype, you cannot use two different entity services for them at the same time. For example, if E1 has a subtype E1SF, only the main service E1ESV is used when storing data, even if both have their own session services.

Conclusion βœ…

Entity Services in Uniface are a powerful way to separate your business logic from the presentation layer. They create more structured applications and help avoid repeating code in every component.

Once you start to centralize your business rules with Entity Services, your development workflow will become cleaner and easier to maintain.

Have you used Entity Services in your Uniface projects? Share your thoughts! πŸ’¬

uniface entity services uniface business logic uniface components legacy modernization

Top comments (0)