secondbreakfast
secondbreakfast

Reputation: 4384

Service classes in .NET Web Api?

I noticed that there is not a default created directory called "Services" or anything like that in the default Web Api template. I come from a Grails background where I learned to use service classes to handle application logic and model processing to move it away from the controllers. Because there is not a default directory for such classes (that I know of) in Web API it leads me to believe that this isn't best practice here. Anyone care to shed some knowledge on this?

Upvotes: 1

Views: 847

Answers (2)

CodeCaster
CodeCaster

Reputation: 151604

Well, "Service" is a misnomer in that regard, you could as well call it a "Manager".

Web API does not dictate any project layout. It just utilizes storing models and controllers, the rest of the layout is yours to decide. You can as well rename the Controllers and Models directories if you'd like.

Of course it's recommended to develop your business logic in a separate class library altogether, which promotes abstraction, separation of concern and hence testability.

Upvotes: 3

Alexander Puchkov
Alexander Puchkov

Reputation: 5973

Keeping application logic in "Services" directory, separately from controller is a good approach regardless of technology stack. Such approach is used by many in .NET world as well.

Default templates are not perfect, so feel free to structure the application the way you used to.

Upvotes: 1

Related Questions