I am making the structure of a .Net based application. For now, I am using MVC 5. Here are details of different components of the system.
1. Database – This is underlying database and will contain the data
2. OData API – This API will interact with database and will perform database related operations only (CRUD). I want this API to be only platform to access and manipulate data. It would provide the functionality to retrieve data through different means (IQueryable, SQL query, Stored Procedure).
3. Business Service – It would consist of two things. Engine and API. Engine would have business logic in it which could include business rules for example WorkflowEngine would handle all the workflow actions. Resident Workflow Action (CRUD Ops) and Non-Resident Workflow Actions (Submit, Approve, Send Back). API will communicate between UI and Engine. Engine will then run the business logic and will communicate with OData. BusinessAPIs will be proprietary APIs and access to these APIs will be subscription based (paid access).
4. UI – User interface will be MVC based and will only interact with Business APIs and will only responsible for displaying the data and sending the data back to BusinessAPIs.
It looks like an N-Layed architecture. If i introduce interfaces, would it be comparable to ONION Architecture.
How can i convert it to ONION Architecture without compromising the security, scalability and performance.
An Onion architecture is essentially an n-teired architecture utilising dependency injection. For example consider an application which takes some numbers, adds them and displays the result.
N tiered:
Data Access Layer:
public class SqlNumbersGetter
{
public List<int> GetNumbers() => ...
}
Business Logic Layer:
public class Summer
{
public int GetSum() => new SqlNumbersGetter().GetNumbers().Sum();
}
Gui Layer:
public class ConsoleDisplayer
{
public void Display() => Console.WriteLine( new Summer().GetSum());
}
The onion architecture is very similar, but we now use interfaces and dependency injection:
Data Access Layer:
public interface INumbersGetter
{
List<int> GetNumbers();
}
public class SqlNumbersGetter : INumbersGetter
{
public List<int> GetNumbers() => ...
}
Business Logic Layer:
public interface ISummer
{
int GetSum(INumbersGetter numberGetter);
}
public class Summer : ISummer
{
public int GetSum(INumbersGetter numberGetter) => numberGetter.GetNumbers().Sum();
}
Gui Layer:
public interface IDisplayer
{
public void Display(ISummer summer, INumbersGetter numberGetter)
}
public class ConsoleDisplayer : IDisplayer
{
public void Display(ISummer summer, INumbersGetter numberGetter) => Console.WriteLine(summer.GetSum(numberGetter));
}
Then you would have your application instantiate all the instances of the interfaces, and link them all up
public void Main()
{
new ConsoleDisplayer().Display(new Summer(), new SqlNumbersGetter());
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With