Answer the question
In order to leave comments, you need to log in
Modular architecture and UnitOfWork pattern in c#?
Hello. Specially registered. Maybe I'll get an answer to my question here.
I am writing a program using modular architecture. That is, I have a "Kernel", and plug-ins use objects, events and other things that the kernel gives. The core is divided into layers. One of the layers is the "Data Access Layer", DAL for short, which allows access to the database. The main task of this layer is to abstract from the data source, since I need to support both mysql and postgresql. For data access, I decided to use the UnitOfWork pattern, since I need to control transactions. An example of this pattern can be found, for example, here https://metanit.com/sharp/mvc5/23.3.php
In this example, there are only 2 entities (tables). I have 15 tables and therefore my UnitOfWork has 15 properties.
Everything is great - I don't write repetitive code, I can easily change the database.
As I said earlier, I have a modular architecture. When a module is connected, an Instance of the UnitOfWork class is passed to it and, accordingly, the module can use all fields (table repositories) and access their properties.
Here is where I have a problem. That is, if the module needs to create its own table or use additional functionality, then it cannot do this, because the UnitOfWork instance does not have properties and certain methods. How to do it right so that the Kernel does not adapt to the modules, but the modules adapt to the kernel. And it was the modules that used the kernel tools for comfortable work with the database.
Injecting separate "Tables" into methods is not a good idea - up to 12 tables can be used in one module.
How to make it all extensible and independent? In the php world like Laravel, a lot of people just create model instances inside controllers - but that's like phew.
By the way, if I write under the desktop.
Answer the question
In order to leave comments, you need to log in
When a module is connected, an Instance of the UnitOfWork class is passed to it and, accordingly, the module can use all fields (table repositories) and access their properties.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question