Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between "service" and "component"?

Tags:

c#

I am little bit confused about the difference between a service and component. Can someone explain with example that what is the difference between a service and component?

like image 601
santosh singh Avatar asked Jun 23 '11 17:06

santosh singh


People also ask

Is a component a service?

That is to say that a service can be deployed separately from the rest of your systems and applications. Services are designed to maximize reuse as opposed to being designed to fit a particular system or application. Components are parts of a system or application that are designed to work together.

Can I use @component instead of @service?

If your component is a generic component, not really living at the service layer, or is accessible but could hold state, then use @Component . If your component is a specific service, living at the service layer, or is accessible and does not inherently hold state, use @Service .

What happens if we use @component instead of @service?

If we use @Component instead of @Service, it becomes more challenging to identify which @Component actually has the service methods – since we may have many other @Component Classes. This means that our AOP Pointcut has to be more specific which introduces some potential issues.

What is the difference between @component @service and controller?

@Component is a generic stereotype for any Spring-managed component or bean. @Repository is a stereotype for the persistence layer. @Service is a stereotype for the service layer. @Controller is a stereotype for the presentation layer (spring-MVC).


2 Answers

A service can be made up of several components. Usually a service provides one complete feature that is made up by combining different components.

The service's user don't need to know anything about the underlying components. User will deal only directly with the service while service internally will be interacting with the components

like image 73
Haris Hasan Avatar answered Oct 17 '22 22:10

Haris Hasan


Services are applications that are (generally) designed to be long running, tied to the operations of the system rather than a user and provide a utility to other applications. Databases, SMTP, Active Directory are all examples of "Services".

Components are pre-formed pieces that can be included in other applications and are not designed to operate 'on their own'. An application that references a database my use a data component (SQLClient) to communicate with a date base service (MS SQL Server).

like image 20
Cos Callis Avatar answered Oct 17 '22 22:10

Cos Callis