A service class in the Znode ecosystem is usually the last managed tier which breaks a requested user operation into several small-sized business logic instructions, data handling, and database transactions. It resides in the “Znode.Engine.Services” namespace.
The service classes are usually constructor-injected into API controllers or in some cases Cache helper classes.
Creating a Service
Assuming that the Znode’s visual studio solution already has custom class library projects created with “Znode.Custom.Engine.Services” and “Znode.Custom.Engine.Api” namespaces, creating a new service class can be accomplished with the following steps:
Create a new interface with an appropriate name suffixed with the word “service” in the newly created custom class library project.
Create a new class with a similar name to the interface (just exclude the letter “I” in the beginning). This class should inherit the “BaseService.cs” as well as implement the newly created service interface.
Make sure that all the new service interfaces and service classes reside within the “Znode.Custom.Engine.Services” namespace.
In the service interface, define all the members which are to be exposed to other components of Znode.
Implement all the exposed members in the child service class. The service class can also contain private members which are only to be used within the scope of this class itself.
Once the service interface and service class are ready to be used, make sure to register them both into the dependency registry which can be found in the “DependencyRegistration.cs” class under “Znode.Custom.Engine.Api” namespace.