Aspnetcore.docs: Mention about Services

Created on 7 Aug 2018  Â·  9Comments  Â·  Source: dotnet/AspNetCore.Docs

I've recently started learning web-dev using ASP.Net Core and what i understand is that in ASP.Net Core MVC, the model is just an entity object that is mapped to the database. Due to this the Business logic get's concentrated into the Controllers and Code Sharing is hindered. To avoid this ASP.Net Core supports Services, but the documentation doesn't mention much in this context about the services. So, getting a mention of the Services at this page will give the reader introduction about using services.


Document Details

⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

P4 Source - Docs.ms

Most helpful comment

Let me chime in here as author of some of the content you're referencing.

The Model in MVC refers to not just a given ViewModel or Entity, but to the domain model or application model, which may include services. You won't find any of the typical UI design patterns including "services" in their names (MVC, MVP, MVVM, etc) because services are a part of the Model in these patterns. Services is also an ambiguous term, since there can be services at any/all levels of abstraction. You can have a "service" that exists only in the UI layer for performing some UI work. You can have a "service" that exists only in an infrastructure library for performing some low level detailed work. And as I mentioned you can have "services" in your domain model providing business logic (in addition to logic that may be on entities and value objects, etc. in the domain model).

This link provides some more info: https://deviq.com/kinds-of-models/ Note when referring to the domain model:

The domain model will often include abstractions and services that allow the Controller to operate at a higher level of abstraction, and keep low-level plumbing code from cluttering the Controller and making it harder to test.

All 9 comments

Hello @Praveen-Rai ... The topic that pertains to services (dependency injection) at https://docs.microsoft.com/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1 appears early in the TOC. Generally, we hope devs will read the major topics in the Fundamentals node before they look at the MVC node.

Also, the topic does have what you're asking for ... https://docs.microsoft.com/aspnet/core/mvc/overview#dependency-injection ... in the Features area of the topic. It links over to the services (DI) topic.

@guardrex It's fair to assume that the developer reads the documentation sequentially, but on the other hand elsewhere as well the MVC pattern does not mention anything about services. May be other frameworks support writing business-logic in the Models, i have absolutely no idea on this as i've just walked first few steps towards web-development and MVC. The point i want to make here is that when a person like me starts with ASP.Net Core MVC, the page under discussion would be the first introduction about MVC from aspnet team. So, it would be better if we talk about MVC in context of ASP.Net Core (where services are the business logic containers) and hence we should at least mention Services and their importance.

Secondly, the links that you pointed talks more about Dependency injection and does not explicitly say that one should create services to contain and share the Business Logic. Again, that might be implied to an expert, but to me DI appears to be an implementation method for Services rather the concept of Service itself ( please correct me if i am mistaken ).

Hope i make sense to you :-)

And how about if we can move this page up in the sequence ?

Thanks for your feedback. I defer to management. @Rick-Anderson @scottaddie

@Rick-Anderson @scottaddie Any comments / updates ??

@Rick-Anderson The links that you provided doesn't cover anything about writing services.

Let me try to express my thoughts again.

Naturally they land up into the controllers ( specifically into the controller actions ). Right ? Now suppose that you're writing another controller and you need to perform some activity which has been already written into an existing controller. As per my understanding that piece of code ( common code to be shared across controllers ) must go into a service. Right ? And referring to https://docs.microsoft.com/en-us/aspnet/core/fundamentals/dependency-injection?view=aspnetcore-2.1#overview-of-dependency-injection it is suggested to use Services over a plain common class.

So summing it all up, the term Model used in MVC when looked in context of Asp.Net Core MVC is a combination of Model (EF Model / Model for DBContext) + Service. I might be wrong here and please correct me if so. But, this is what missing from the present documentation. Clearly, what stated in Model-responsibilities in the underlying article, is achieved with a combination of Model and Service. Hence, we must mention about Services, their relationship with Models ( entity mode ), Views and Controllers, and articles related to them.

Hope this explanation helps and i make sense to you now.

Let me chime in here as author of some of the content you're referencing.

The Model in MVC refers to not just a given ViewModel or Entity, but to the domain model or application model, which may include services. You won't find any of the typical UI design patterns including "services" in their names (MVC, MVP, MVVM, etc) because services are a part of the Model in these patterns. Services is also an ambiguous term, since there can be services at any/all levels of abstraction. You can have a "service" that exists only in the UI layer for performing some UI work. You can have a "service" that exists only in an infrastructure library for performing some low level detailed work. And as I mentioned you can have "services" in your domain model providing business logic (in addition to logic that may be on entities and value objects, etc. in the domain model).

This link provides some more info: https://deviq.com/kinds-of-models/ Note when referring to the domain model:

The domain model will often include abstractions and services that allow the Controller to operate at a higher level of abstraction, and keep low-level plumbing code from cluttering the Controller and making it harder to test.

I agree with @Praveen-Rai. The role of the services are not emphazised enough. I (as a newbie asp.net core MVC developer) started adding all the business logic into the controller. In my opinion this page should guide the readers when they are trying to learn the recommended or best practices to implement the MVC pattern using this framework, and the services are an integral part of that.

Was this page helpful?
0 / 5 - 0 ratings