Search code examples
.net-coreasp.net-core-webapistructure

.NET separate backend and WebAPI or not


I am fairly new to .NET and I need to do a project that provides a web interface for messages.

The question is:

  • Should I separate the backend and the WebAPI?

So should I create a .NET Core Console Application for the Backend and one .NET Core WebAPI for the API and so the backend will communicate with the API to store and read from DB.

OR

Should I create a .NET Core WebAPI Project that contains both (Backend and API)?

The Backend will do background tasks (Message handling etc.)

If I do not separate (so put everything in .NET Core WebAPI), how should I create Background Thread that runs as long as the app runs?

(I do not want to use HangFire or Quartz)


Solution

  • In my opinion, you should seperate the projects since there are so many use case differences.

    An API endpoint, for example, often is designed to deliver loads of data from an endpoint while the same data access from a web application most likely will be more restricted and filtered. Also you while most likely have different authorization concepts to use for api (JWT Token f.e.) or web application backend (Basic User Authentication).

    Further developments and maintenance will be much easier if you seperate the services also because you can always garantuee not to have dependencies between each other.

    You also have much more reuseablitiy as well due to the fact that you are able to deliver either both services or only one of both.