Services

All businesses are implemented in the form of services and created in the service layer. The service layer uses the Service Infrastructure layer and automatically connects to each service in its own Repository. The advantage of this approach is that the developer is not involved in the two concepts of repository and service and focuses only on the service itself. The service has its own built-in Repository, which is one of the most important features of the AUA framework architecture. For example, if we want to write a service for Student Entity, we need to first create an interface for Student Entity which inherits from the IGenericEntityService class. At the third step we need to create a Service in Services directory. The service must inherit from the GenericEntityService class and implement the IStudentService interface built in the previous step. By default, the service created contains all the functions required to work with Repository. List of Repository functions that are automatically added to each service. Implement the business into the services. One service can use other services. You can easily inject services into another and use it.

Service Types

Service Description
Entities Service These types of services are for working with entities and have a repository inside, Moreover, the business related to each entity is written in each service.
Business Service This type of service is intended for the implementation of businesses.
General Service General services that are used throughout the application, such as the login service - JWT Token service.
List Service Quick Report Service - To write quick operational reports.
Report Service A service used for getting Enterprise reports.
SQL Function Service A service used for access to SQL Function and Stored procedure.
Validation Service Services to validate the view models sent by clients.
Log Service Logging service.
InMemory Service Services used for working with in-memory data.
Views Service Services used for working with SQL Service views.
External Service Services used for working with the external service.
External Service Provider Services to cover and match external services with the Core Domain.

Entity Service

All the following functions are in three forms:
  1. Asynchronous
  2. Synchronous
  3. Asynchronous with CancellationToken

Function Description
Insert(dto) Insert a DTO
Insert(entity) Insert an Entity
InsertAsync(dto) Insert a DTO asynchronously
InsertAsync(entity) Insert an Entity asynchronously
InsertCustomVmAsync(customVm) Inserting a View Model the synchronous fields of which are inserted asynchronously.
InsertCustomVm(customVm) Inserting a View Model the synchronous fields of which are inserted in the table.
PartialInsert(dto) Save Entity in DbContext without inserting it in the table. You can insert or update multiple Entities and save these entities together. With a SaveChangesAsync () or SaveChange () command
PartialInsert(entity) Save Entity in DbContext without inserting it in the table. You can insert or update multiple Entities and save these entities together. With a SaveChangesAsync () or SaveChange () command
InsertMany(IEnumerable<dto>) Insert multiple Entities / DTOs synchronously
InsertManyAsync(IEnumerable<dto>) Insert multiple Entities / DTOs simultaneously asynchronously
Delete(id) Delete an Entity by Id
Delete(dto) Delete an Entity by DTO
Delete(entity) Delete an Entity
DeleteAsync(id) Delete an Entity by Id asynchronously
DeleteAsync(dto) Delete an Entity by DTO asynchronously
DeleteAsync(entity) Delete an Entity asynchronously
TryDelete(id) Delete an Entity by Id that returns true if deleted otherwise False
TryDelete(dto) Delete an Entity by DTO that returns true if deleted otherwise False
TryDelete(entity) Delete an Entity that returns true if deleted otherwise False
TryDeleteAsync(id) Delete an Entity by Id that returns true if deleted otherwise false, asynchronously
TryDeleteAsync(dto) Delete an Entity by DTO that returns true if deleted otherwise false, asynchronously
TryDeleteAsync(entity) Delete an Entity that returns true if deleted otherwise false, asynchronously
Update(dto) Update an Entity by DTO
Update(entity) Update an Entity
UpdateAsync(dto) Update an Entity by DTO, asynchronously
UpdateAsync(entity) Update an Entity, asynchronously
UpdateCustomVm(customVm) Edit Entity Fields by CustomVm
UpdateCustomVmAsync(customVm) Edit Entity Fields by CustomVm, asynchronously
PartialUpdate(dto) Updating an Entity in DbContext without inserting it in the table. You can insert or update multiple entities and save them together using the SaveChangesAsync() or SaveChanges() command.
PartialUpdate(entity) Updating an Entity in DbContext without inserting it in the table. You can insert or update multiple entities and save them together using the SaveChangesAsync() or SaveChanges() command.
SoftDelete(id) Deleting the record by Id logically and the two fields including IsDelete and DeletedDate get values.
SoftDeleteAsync(id) Deleting the record by Id logically and the two fields including IsDelete and DeletedDate get values, asynchronously.
SoftDelete(entity) Deleting the record by entity logically and the two fields including IsDelete and DeletedDate get values
SoftDeleteAsync(entity) Deleting the record by entity logically and the two fields including IsDelete and DeletedDate get values, asynchronously
SoftDelete(dto) Deleting the record by Dto logically and the two fields including IsDelete and DeletedDate get values
SoftDeleteAsync(dto) Deleting the record by Dto logically and the two fields including IsDelete and DeletedDate get values, asynchronously
GetById(id) Getting Entity by Id
GetDtoById(id) Getting DTO by Id
GetByIdAsync(id) Getting Entity by Id, asynchronously
GetDtoByIdAsync(id) Getting DTO by Id, asynchronously
GetCount() Getting the count
GetCountAsync() Getting the count, asynchronously
FirstOrDefault() Getting the first Record
FirstOrDefaultAsync() Getting the first Record, asynchronously
GetAll() Getting Entities as ToList - ToListAsync
GetAllDto() Getting DTOs as ToList - ToListAsync
GetByPredicate() Getting entities by predicate
GetCountAsync() Getting the Count asynchronously

Below we create a service for the AppUser entity. First, we need to create an interface for the service.


Interface:
            
public interface IAppUserService : IGenericEntityService<AppUser, AppUserDto>
{
}


Service:
            
public class AppUserService : GenericEntityService<AppUser, AppUserDto>, IAppUserService
{
    public AppUserService(IUnitOfWork unitOfWork) : base(unitOfWork)
    {
    }
}


Services in youtube More videos

Services in youtube More videos

Business Service

Business services are used to implement businesses. If the business is small, it can be written in the same Entities Services, but if the business is an important or medium or large business, it can be implemented from the business services and a separate service can be considered for that business. However, it is recommended that you consider a separate service for any business, which will make the code cleaner. Other services such as Entity Services can be used in business services. Business services such as the Fa├žade design pattern can cover your business. Using business services has many benefits, including preventing circular dependency injection and making code maintenance easier.


Business Services in youtube More videos

Business Services in youtube More videos

Generic Service

Generic services are used for generic works such as producing access tokens. In these services, all different types of services can be used. These services are not part of the main business, but they are needed in the project.

SQL Function Service

These services are used for working with SQL Stored Procedure and SQL Functions. For the convenience of working with SQL Stored Procedure, the programmer often follows other ways such as Ado.net, Dapper, unaware of the fact that he can manage the number of connections made or create a separate context for it. This (SQL Stored Procedure call) can be done easily in the AUA framework and does not have any of the problems mentioned. Framework services allow you to query the output of the procedure. However, this is not the right way and it is better to write your own procedure for each task. The AUA framework allows you to easily call SQL functions and procedures and get the right output in the form of DTOs.

Validation Service

One of the most important and interesting services of the AUA framework is the validation services. All requests sent to the AUA framework must first be validated. If the request is valid, it will be processed. This validation can include the validation of data structure, foreign keys, etc. You can easily write your own validation for each View Model. This will increase the performance and also prevent resources from being wasted. The structure of validation services is such that we can easily work with them and add one validation service within a few minutes. Validation services have a very interesting and simple structure that can support multiple errors. The following is an example of a validation service for validating the View Model.


Validation Services in youtube More videos

Validation Services in youtube More videos

Log Service

These services are used for logging, helping save any type of log in different data sources, such as SQL server, file, elastic search, etc.
Information = 1,
Warning = 2,
Error = 3,
Danger = 4,
Exception =5
We can have different high-speed logs inside the services as well as inside the controls.

InMemory Service

To increase the speed, we often need to store our data in RAM so that we may not need to take it from the database. This data is usually stored as In Memory, which has a small volume and is rarely used for changes. For example, basic information or user access can be stored as In Memory. When storing data in this way, we must consider many points and have a mechanism for updating the data so that the data can receive the changes if any. The AUA framework has a very simple and fast structure for this. You can systematically store data as In Memory locally in the memory of the server system or use databases that are used for data In Memory such as Redis.

Views Service

View is a logical collection of tables in SQL server stored in the SQL database. It is a virtual table that does not exist physically but is created by joining the tables in SQL. One of the concerns of .NET programmers is working with SQL Views in such a way that they can map their results to objects and filter the output of views. The Entity Framework recognizes views as tables, but the AUA framework makes it possible to map the output of views inside objects and apply filters to them.

External Service

An application is never on an island. It needs to communicate with other applications and use their data and capabilities to do their job. Today, the use of third parties has become very common. We need to have a proper structure for services to communicate with them. External Services are services that allow you to communicate with external services, such as sending SMS - banking portals etc. When using the Micro service architecture, we can communicate with other systems using the External Service.

External Provider Service

External Provider Services are services for converting the entities of the external system to entities that are compatible with the Core Domain entities - all conversions of types are done in the External Service Provider and the External Service is responsible only for calling external services.