0
votes

We're designing a layered business application in .net/c# and we are trying to follow the SOLID-principles as much as we see fit. Testability is very important in our project and for this purpose we are using Moq. Using moq we are, among other things, mocking our entity framework context.

As the main goal for our testing is the main business layer (BL) logic, the business layer classes can be injected with the Data Access Layer (DAL) context to use. See example below. sample constructor of a BL class responsible for loading data. This class injects dependencies for setting access, etc.

    public LoadDataProcess(KonstruktEntities context, IDataLoadedChecker dataLoadedChecker, ILoadUserBudgetData dataLoader, ISetLineAccess setBudgetLineStatus, ILineAccessFilterHandler budgetDataLineStatusFilterHandler) 
    {
        _context = context;
        _dataLoadedchecker = dataLoadedChecker;
        _dataLoader = dataLoader;
        _setBudgetLineStatus = setBudgetLineStatus;
        _budgetDataLineStatusFilterHandler = budgetDataLineStatusFilterHandler;
    }

Now, there are also other DAL dependencies that can be injected into our BL classes. Since these objects are beeing instanciated in the Service Layer (WCF) I don't like that DAL components can be injected.

Question is, should we be injecting DAL dependencies into BL classes at all?

1
If you're trying to apply SOLID to your business layer, do take a look at this, this and this article, since they can make a tremendous difference in maintainability and flexibility of your application.Steven
will have a look at these, thanks. What do you think about the question I asked?JohanLarsson

1 Answers

1
votes

Since your BL depends upon abstractions, your are adhering to the Dependency Inversion Principle (DIP). It's obvious that your business layer needs to communicate with the DAL; there's really no way around this, but since your are depending upon abstractions instead of low level components, this will be fine.