Home

Awesome

Visual Studio Marketplace version Visual Studio Marketplace downloads Visual Studio Marketplace ratings Visual Studio Marketplace version


.NET Core Bugs Code Smells Duplicated Lines (%) Maintainability Rating Quality Gate Status Vulnerabilities Security Rating GitHub license

WhiteApp/QuickApp Onion architecture with ASP.NET Core

<br /> <p align="center"> <a href="#"> <img src="docs/img/OnionArchitecture_icon.png" alt="Logo" width="80" height="80"> </a> <h3 align="center">Onion Architecture</h3> <p align="center"> WhiteApp or QuickApp API solution template which is built on Onion Architecture with all essential feature using .NET Core! <br /> <a href="https://amitpnk.github.io/Onion-architecture-ASP.NET-Core/"><strong>Explore the docs »</strong></a> <br /> <br /> <a href="https://marketplace.visualstudio.com/items?itemName=AmitNaik.OnionArchitecture">Download from Marketplace</a> · <a href="https://github.com/Amitpnk/Onion-architecture-ASP.NET-Core/issues">Report Bug</a> · <a href="https://github.com/Amitpnk/Onion-architecture-ASP.NET-Core/issues/new">Request Feature</a> </p> </p>

Give a Star! :star:

If you like or are using this project to learn or start your solution, please give it a star. Thanks!

Support This Project

If you have found this project helpful, either as a library that you use or as a learning tool, please consider buying me a coffee:

<a href="https://www.buymeacoffee.com/codewithamit" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important" ></a>

<!-- TABLE OF CONTENTS -->

Table of Contents

<!-- * [Acknowledgements](#acknowledgements) -->

Onion Architecture

Onion Architecture was introduced by Jeffrey Palermo to provide a better way to build applications in perspective of better testability, maintainability, and dependability on the infrastructures like databases and services

Onion, Clean or Hexagonal architecture: it's all the same. Which is built on Domain-Driven Desgin approach.

Domain in center and building layer top of it. You can call it as Domain-centric Architecture too.

Reference

About The Project

<!-- [![Product Name Screen Shot][product-screenshot]](https://example.com) -->

WhiteApp or QuickApp API solution template which is built on Onion Architecture with all essential feature using .NET Core.

image

Getting Started

Step 1: Download extension from project template

<p> <a href="https://marketplace.visualstudio.com/items?itemName=AmitNaik.OnionArchitecture">Download from Marketplace</a></p>

image

Step 2: Create Project

Select project type as API, and select Onion Architecture

image

Step 3: Select Onion Architecture project template

Select project type as API, and select Onion Architecture

image

Step 4: Project is ready

image

Step 5: Configure connection string in appsettings.json

Make sure to connect proper database

  "ConnectionStrings": {
    "OnionArchConn": "Data Source=(local)\\sqlexpress01;Initial Catalog=OnionDb;Integrated Security=True",
    "IdentityConnection": "Data Source=(local)\\sqlexpress01;Initial Catalog=OnionDb;Integrated Security=True"
  }, 

and connect to logging in DB or proer path

  "Serilog": {
    "MinimumLevel": "Information",
    "WriteTo": [
      {
        "Name": "RollingFile",
        "Args": {
++          "pathFormat": "D:\\Logs\\log-{Date}.log",
          "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level}] {Message}{NewLine}{Exception}"
        }
      },
      {
        "Name": "MSSqlServer",
        "Args": {
++          "connectionString": "Data Source=(local)\\sqlexpress01;Initial Catalog=OnionDb3;Integrated Security=True",
          "sinkOptionsSection": {
            "tableName": "Logs",
            "schemaName": "EventLogging",
            "autoCreateSqlTable": true
          },
          "restrictedToMinimumLevel": "Warning"
        }
      }
    ],
    "Properties": {
      "Application": "Onion Architecture application"
    }
  },

Step 6: Create Database (Sample is for Microsoft SQL Server)

For Code First approach (To run this application, use Code First apporach)

For Database First approach

In Package Manager console in << ProjectName >>.Persistence, run below command

scaffold-dbcontext -provider Microsoft.EntityFrameworkCore.SqlServer -connection "Data Source=(local)\SQLexpress;Initial Catalog=OnionArchitectureDB;Integrated Security=True"

Step 7: Build and run application

Health check UI

Navigate to Health Checks UI https://localhost:44356/healthcheck-ui and make sure everything is green.

** Change port number according to your application

image

Swagger UI

Swagger UI https://localhost:44356/OpenAPI/index.html

** Change port number according to your application

image

Features available in this project

This is default white application for ASP.NET Core API development

This whiteapp contains following features, uncheck feature need to implement yet.

Below features will be implemented in infrastructure layer. You can plug and play based on your project.

Project description

we can see that all the Layers are dependent only on the Core Layers

<details> <summary><b>Domain layer</b></summary> <p> Domain Layers (Core layer) is implemented in center and never depends on any other layer. Therefore, what we do is that we create interfaces to Persistence layer and these interfaces get implemented in the external layers. This is also known and DIP or Dependency Inversion Principle </p> </details> <details> <summary><b>Persistence layer</b></summary> <p> In Persistence layer where we implement reposistory design pattern. In our project, we have implement Entityframework which already implements a repository design pattern. DbContext will be UoW (Unit of Work) and each DbSet is the repository. This interacts with our database using dataproviders </p> </details> <details> <summary><b>Service layer</b></summary> <p> Service layer (or also called as Application layer) where we can implement business logic. For OLAP/OLTP process, we can implement CQRS design pattern. In our project, we have implemented CQRS design pattern on top of Mediator design pattern via MediatR libraries </p> <p>In case you want to implement email feature logic, we define an IMailService in the Service Layer. Using DIP, it is easily possible to switch the implementations. This helps build scalable applications. </p> </details> <details> <summary><b>Infrastructure Layer</b></summary> <p> In this layer, we add our third party libraries like JWT Tokens Authentication or Serilog for logging, etc. so that all the third libraries will be in one place. In our project, we have implemented almost all important libraries, you can plug & play (add/remove) based on your project requirement in StartUp.cs file. </p> </details> <details> <summary><b>Presentation Layer</b></summary> <p> This can be WebApi or UI. </p> </details>

Licence Used

GitHub license

See the contents of the LICENSE file for details

Contact

Having any issues or troubles getting started? Drop a mail to amit.naik8103@gmail.com or Raise a Bug or Feature Request. Always happy to help.