Understanding the difference between ONION and N-Layered architecture












1















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. Dependency DiagramProject Dependency










share|improve this question























  • Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

    – Joe
    Nov 25 '18 at 13:40
















1















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. Dependency DiagramProject Dependency










share|improve this question























  • Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

    – Joe
    Nov 25 '18 at 13:40














1












1








1


1






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. Dependency DiagramProject Dependency










share|improve this question














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. Dependency DiagramProject Dependency







.net architecture software-design onion-architecture n-layer






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 11:54









Saud NasirSaud Nasir

184




184













  • Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

    – Joe
    Nov 25 '18 at 13:40



















  • Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

    – Joe
    Nov 25 '18 at 13:40

















Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

– Joe
Nov 25 '18 at 13:40





Some crusty old-timers might find it difficult to distinguish ONION from a classic 3-tier architecture that respects SOLID principles :)

– Joe
Nov 25 '18 at 13:40












2 Answers
2






active

oldest

votes


















0














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());
}





share|improve this answer































    0














    In short, Onion architecture help you to build a loose couple system, somehow like a plugin sys. You have in the center the Businesses logic, the core, everything else (User interface client, third party library, database repository and so on) could be change without the need to change something in this core layer.



    It is a good architecture following the SOLID principles:




    • each part has Single responsibility, gather together the things that change for the same reasons.You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.


    • Open Closed Principle: programming to interface so that you can change the actual implementation without ripple effect for the client module "



    “When there is a new requirement, you could add new features to that system without modifying any old code. The features would be added solely by writing new code.” Uncle Bob





    • The Liskov Substitution Principle and Interface Segregation Principle it is more for the way you construct the classes, shortly: favor composition vs. inheritance and if a component of your system is only interested in a subset of the methods of a class, give that component an interface to the class containing only the subset of methods it is interested in


    • Dependency Inversion Principle: Your high level policy components should not depend on low level detail components. The interface should be decided by the high level component and the detail has to conform to it.For example your core layer should not depend on the implementation of the user interface, the user interface should depend on the core trough interfaces.



    Here you can find a detail explanation of the onion architecture:
    Victor Rentea - The Art Of Clean Code:
    https://www.youtube.com/watch?v=c0L7EdsxQ_c



    The design schema:
    onion architecture






    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467160%2funderstanding-the-difference-between-onion-and-n-layered-architecture%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      0














      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());
      }





      share|improve this answer




























        0














        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());
        }





        share|improve this answer


























          0












          0








          0







          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());
          }





          share|improve this answer













          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());
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 25 '18 at 15:18









          Yair HalberstadtYair Halberstadt

          1,031422




          1,031422

























              0














              In short, Onion architecture help you to build a loose couple system, somehow like a plugin sys. You have in the center the Businesses logic, the core, everything else (User interface client, third party library, database repository and so on) could be change without the need to change something in this core layer.



              It is a good architecture following the SOLID principles:




              • each part has Single responsibility, gather together the things that change for the same reasons.You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.


              • Open Closed Principle: programming to interface so that you can change the actual implementation without ripple effect for the client module "



              “When there is a new requirement, you could add new features to that system without modifying any old code. The features would be added solely by writing new code.” Uncle Bob





              • The Liskov Substitution Principle and Interface Segregation Principle it is more for the way you construct the classes, shortly: favor composition vs. inheritance and if a component of your system is only interested in a subset of the methods of a class, give that component an interface to the class containing only the subset of methods it is interested in


              • Dependency Inversion Principle: Your high level policy components should not depend on low level detail components. The interface should be decided by the high level component and the detail has to conform to it.For example your core layer should not depend on the implementation of the user interface, the user interface should depend on the core trough interfaces.



              Here you can find a detail explanation of the onion architecture:
              Victor Rentea - The Art Of Clean Code:
              https://www.youtube.com/watch?v=c0L7EdsxQ_c



              The design schema:
              onion architecture






              share|improve this answer




























                0














                In short, Onion architecture help you to build a loose couple system, somehow like a plugin sys. You have in the center the Businesses logic, the core, everything else (User interface client, third party library, database repository and so on) could be change without the need to change something in this core layer.



                It is a good architecture following the SOLID principles:




                • each part has Single responsibility, gather together the things that change for the same reasons.You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.


                • Open Closed Principle: programming to interface so that you can change the actual implementation without ripple effect for the client module "



                “When there is a new requirement, you could add new features to that system without modifying any old code. The features would be added solely by writing new code.” Uncle Bob





                • The Liskov Substitution Principle and Interface Segregation Principle it is more for the way you construct the classes, shortly: favor composition vs. inheritance and if a component of your system is only interested in a subset of the methods of a class, give that component an interface to the class containing only the subset of methods it is interested in


                • Dependency Inversion Principle: Your high level policy components should not depend on low level detail components. The interface should be decided by the high level component and the detail has to conform to it.For example your core layer should not depend on the implementation of the user interface, the user interface should depend on the core trough interfaces.



                Here you can find a detail explanation of the onion architecture:
                Victor Rentea - The Art Of Clean Code:
                https://www.youtube.com/watch?v=c0L7EdsxQ_c



                The design schema:
                onion architecture






                share|improve this answer


























                  0












                  0








                  0







                  In short, Onion architecture help you to build a loose couple system, somehow like a plugin sys. You have in the center the Businesses logic, the core, everything else (User interface client, third party library, database repository and so on) could be change without the need to change something in this core layer.



                  It is a good architecture following the SOLID principles:




                  • each part has Single responsibility, gather together the things that change for the same reasons.You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.


                  • Open Closed Principle: programming to interface so that you can change the actual implementation without ripple effect for the client module "



                  “When there is a new requirement, you could add new features to that system without modifying any old code. The features would be added solely by writing new code.” Uncle Bob





                  • The Liskov Substitution Principle and Interface Segregation Principle it is more for the way you construct the classes, shortly: favor composition vs. inheritance and if a component of your system is only interested in a subset of the methods of a class, give that component an interface to the class containing only the subset of methods it is interested in


                  • Dependency Inversion Principle: Your high level policy components should not depend on low level detail components. The interface should be decided by the high level component and the detail has to conform to it.For example your core layer should not depend on the implementation of the user interface, the user interface should depend on the core trough interfaces.



                  Here you can find a detail explanation of the onion architecture:
                  Victor Rentea - The Art Of Clean Code:
                  https://www.youtube.com/watch?v=c0L7EdsxQ_c



                  The design schema:
                  onion architecture






                  share|improve this answer













                  In short, Onion architecture help you to build a loose couple system, somehow like a plugin sys. You have in the center the Businesses logic, the core, everything else (User interface client, third party library, database repository and so on) could be change without the need to change something in this core layer.



                  It is a good architecture following the SOLID principles:




                  • each part has Single responsibility, gather together the things that change for the same reasons.You want to isolate your modules from the complexities of the organization as a whole, and design your systems such that each module is responsible (responds to) the needs of just that one business function.


                  • Open Closed Principle: programming to interface so that you can change the actual implementation without ripple effect for the client module "



                  “When there is a new requirement, you could add new features to that system without modifying any old code. The features would be added solely by writing new code.” Uncle Bob





                  • The Liskov Substitution Principle and Interface Segregation Principle it is more for the way you construct the classes, shortly: favor composition vs. inheritance and if a component of your system is only interested in a subset of the methods of a class, give that component an interface to the class containing only the subset of methods it is interested in


                  • Dependency Inversion Principle: Your high level policy components should not depend on low level detail components. The interface should be decided by the high level component and the detail has to conform to it.For example your core layer should not depend on the implementation of the user interface, the user interface should depend on the core trough interfaces.



                  Here you can find a detail explanation of the onion architecture:
                  Victor Rentea - The Art Of Clean Code:
                  https://www.youtube.com/watch?v=c0L7EdsxQ_c



                  The design schema:
                  onion architecture







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 26 '18 at 3:06









                  lda573lda573

                  427




                  427






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53467160%2funderstanding-the-difference-between-onion-and-n-layered-architecture%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      Contact image not getting when fetch all contact list from iPhone by CNContact

                      count number of partitions of a set with n elements into k subsets

                      A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks