Step 5 Create the work interface class files unit, which statement the IDemoUnitOfWork interface variables. It collects the interface class of the BLL and other functions of the generic repository.

Fig 9 IUnitOfWork class file source code

Step 6 Create the work service class files unit, which implements the generic repository’s BLL class files and other functions. Don’t write non-related tasks in this file because this class should focus on how to implement the BLL class files and keep clean code rules, and doesn’t should write the non-related source code in it.

Fig 10 UnitOfWorkServices class file source code

Step 7 Create the client-side, which will be used the source code and the files. It keeps following the dependency injection rule and uses the interface class methods, which also can use the abstract class methods, but the interface class method and the abstract method have a few different characteristics. This article doesn’t include its discussion and descript range. The interface class name sets “IUnitOfWorkClientServices.” The service class name sets “UnitOfWorkClientServices.”

Fig 11 IUnitOfWorkClientServices class file source code
Fig 12 UnitOfWorkClientServices class file source code

Step 8 Create the unit of work pattern-related flies in the web projects, then register the related files in the “Startup.cs.”

// Unit of Work
services.AddScoped(typeof(IUnitOfWorkClientServices<>), typeof(UnitOfWorkClientServices<>));
Fig 13 UnitOfWork pattern result

Reference

Leave a Reply