Kryat Docs Image

Services in MVC

What are Services in ASP.NET Core MVC?

Services in ASP.NET Core MVC are classes that encapsulate business logic, external API interactions, or other operations that support the application but aren't directly related to HTTP request handling (which is the controller's responsibility).

In KikiWriting, services are organized under the Services directory, grouped by feature.

Services help maintain separation of concerns by:

  • Moving business logic out of controllers
  • Making code more testable
  • Enabling reuse across different parts of the application

Services vs. Libraries

ServicesLibraries
Scoped to the applicationCan be used across multiple projects
Registered in dependency injectionImported as project references
Follow application's naming/coding conventionsMay have their own conventions
Can be easily mocked for testingMay be harder to mock if not designed for testability
Can access other application servicesTypically standalone with minimal dependencies

On this page