SlideShare a Scribd company logo
SERVICES
WHY SERVICES
• Image a scenario of a company where employees are assigned tasks based on the nature
of their work. There is a employee Popeye who is the team leader so he has different
responsibilities such as :
• Handle client calls and guide them.
• Generate excel sheets with data for analysis.
• Manage schedule of team members .
• Schedule and look over calls for team members.
As you can see Popeye’s work is too hectic and complicated because all the tasks being
handled by them are of very different nature , he’s more likely to get stressed out and make
mistakes. His errors could cost a lot of money in the long run. Another problem is it's not easy
to replace Popeye as he is too involved in a complicated setup.
Likewise in software, it is not really a great idea to write a class with different responsibilities,
a single class or source file should only be involved in only one nature of task .If there is a lot
of things going on, this will only introduce bugs and problems later as the application will be
very complicated to maintain.
WHY NOT JUST CONTROLLER
Consider a controller in Grails .Inside a controller, we can do the following.
• Handle routing logic.
• Invoke GORM operations to manipulate data in database.
• Render text and show it to user.
However, it is not advisable that we do all those things inside a controller. Grails
allows a developers to do all these things together for flexibility, but it should be
avoided. The real purpose of a controller is to deal with the routing login which
means :
• Receive requests from user.
• Invoke the appropriate business login(services)
• Invoke the view to display result
DON’T REPEAT YOURSELF(DRY)
These days most of the technologies are following the DRY concept
which follows a strict practice of not having to duplicate code, using a
service layer is you could reuse a business logic in multiple places
without code duplication. Having a single copy of a particular business
logic will make a project shorter (in terms of lines of codes) and easier
to maintain. Changing the business logic will just require a change in
only one particular place.
CREATING A SERVICE
- To create a service , you can use create-service command from the root folder of your application.Ex.
grails create-service com.test.Test
The above command would create a TestService in com/test directory path .
- Or you can also create service from your ide.
- Service created would have the following content
package com.test
class TestService{
def serviceMethod(){
}
}
- You can go on adding as many method in the services having same nature of tasks.
INJECTING A SERVICE
• To use service methods , you would need to inject the service .
• Services can be injected in a controller , domain , tag libs,Bootstrap or another service.
• To inject a service in a controller
package com.test
class TestController{
def testService
def saveData(){
testService.serviceMethod()
}
}
TRANSACTION MANAGEMENT
• Transaction is a very important concept. Hope you are well aware of ACID(Atomicity, Consistency, Isolation, Durability)
properties .
• Usually we wish certain sequence of database changes to be successful. If not possible we want no operation to happen at
all.
• Imagine a code that deducts money from one account (accountFrom.balance = accountFrom.balance - amount), and adds
money to another account (accountTo.balance = accountTo.balance + amount). Imagine if something happened (an
Exception) after deducting from the source account and the destination account was not updated. Money will be lost and
not accounted for. For this type of codes, we want an "all or nothing" behavior. This concept is also called atomicity.
• Since Grails supports transactions, it automatically do these things to us when we declare a service to be transactional:
• If all db operations are successful, reflect the changes to the database (this is also called commit)
• If one db operation result in exception, return to the original state and forget/undo all the previous operations (this is also
called rollback)
• By default all services are transactional, if you don’t want transactional behavior of the service you can get rid of it by
class TestService(){
static transactional=false
}
SCOPE
• By default, access to service methods is not synchronized, so nothing prevents concurrent execution of those
methods. In fact, because the service is a singleton and may be used concurrently, you should be very careful
about storing state in a service.
• You You can change this behavior by placing a service in a particular scope. The supported scopes are:
• prototype - A new service is created every time it is injected into another class
• request - A new service will be created per request
• flash - A new service will be created for the current and next request only
• flow - In web flows the service will exist for the scope of the flow
• conversation - In web flows the service will exist for the scope of the conversation. ie a root flow and its sub
flows
• session - A service is created for the scope of a user session
• singleton (default) - Only one instance of the service ever exists
• To enable one of the scopes, add a static scope property to your class whose value is one of the above. Ex
static scope=“session”

More Related Content

What's hot

Creating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using VbaCreating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using Vba
Chester Tugwell
 
How to create a REST pass through in Oracle Service Bus (OSB) 12c
How to create a REST pass through in Oracle Service Bus (OSB) 12cHow to create a REST pass through in Oracle Service Bus (OSB) 12c
How to create a REST pass through in Oracle Service Bus (OSB) 12c
coolaboration
 
Slideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You QueueSlideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You Queue10n Software, LLC
 
Graviton Approval Framework Presentation
Graviton Approval Framework PresentationGraviton Approval Framework Presentation
Graviton Approval Framework Presentationgravitonconsulting
 
Soap ui introduction
Soap ui introductionSoap ui introduction
Soap ui introduction
Ikuru Kanuma
 
Patterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & DataPatterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & Data
Agile Testing Alliance
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
Lee Englestone
 
]project-open[ Workflow Developer Tutorial Part 1
]project-open[ Workflow Developer Tutorial Part 1]project-open[ Workflow Developer Tutorial Part 1
]project-open[ Workflow Developer Tutorial Part 1
Klaus Hofeditz
 
Useful Salesforce.com chrome extensions & Snapshots
Useful Salesforce.com chrome extensions & SnapshotsUseful Salesforce.com chrome extensions & Snapshots
Useful Salesforce.com chrome extensions & Snapshots
ProQuest
 
Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012
Wael Hamze
 
Functions creation in sql
Functions creation in sqlFunctions creation in sql
Webservices(or)SoapUI Interview Questions
Webservices(or)SoapUI Interview QuestionsWebservices(or)SoapUI Interview Questions
Webservices(or)SoapUI Interview Questions
H2kInfosys
 
Learn SoapUI
Learn SoapUILearn SoapUI
Learn SoapUI
David Ionut
 
Angular vs FORWARD
Angular vs FORWARDAngular vs FORWARD
Angular vs FORWARD
Costas Zarifis
 
Web api 2 With MVC 5 With TrainerKrunal
Web api 2 With MVC 5 With TrainerKrunalWeb api 2 With MVC 5 With TrainerKrunal
Web api 2 With MVC 5 With TrainerKrunal
Krunal Trivedi
 
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
KMS Technology
 
Datasense
DatasenseDatasense
Datasense
Krishna_in
 
Testing Web Services - QA or the Highway 2016
Testing Web Services - QA or the Highway 2016Testing Web Services - QA or the Highway 2016
Testing Web Services - QA or the Highway 2016
Steinn 'Stan' Jónsson
 

What's hot (19)

Creating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using VbaCreating A User‑Defined Function In Excel Using Vba
Creating A User‑Defined Function In Excel Using Vba
 
How to create a REST pass through in Oracle Service Bus (OSB) 12c
How to create a REST pass through in Oracle Service Bus (OSB) 12cHow to create a REST pass through in Oracle Service Bus (OSB) 12c
How to create a REST pass through in Oracle Service Bus (OSB) 12c
 
Slideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You QueueSlideshare - Magento Imagine - Do You Queue
Slideshare - Magento Imagine - Do You Queue
 
Graviton Approval Framework Presentation
Graviton Approval Framework PresentationGraviton Approval Framework Presentation
Graviton Approval Framework Presentation
 
Soap ui introduction
Soap ui introductionSoap ui introduction
Soap ui introduction
 
Paper CS
Paper CSPaper CS
Paper CS
 
Patterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & DataPatterns of a "Good" Test Automation Framework, Locators & Data
Patterns of a "Good" Test Automation Framework, Locators & Data
 
MVC Training Part 2
MVC Training Part 2MVC Training Part 2
MVC Training Part 2
 
]project-open[ Workflow Developer Tutorial Part 1
]project-open[ Workflow Developer Tutorial Part 1]project-open[ Workflow Developer Tutorial Part 1
]project-open[ Workflow Developer Tutorial Part 1
 
Useful Salesforce.com chrome extensions & Snapshots
Useful Salesforce.com chrome extensions & SnapshotsUseful Salesforce.com chrome extensions & Snapshots
Useful Salesforce.com chrome extensions & Snapshots
 
Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012Test & Dynamics CRM - extremeCRM Berlin 2012
Test & Dynamics CRM - extremeCRM Berlin 2012
 
Functions creation in sql
Functions creation in sqlFunctions creation in sql
Functions creation in sql
 
Webservices(or)SoapUI Interview Questions
Webservices(or)SoapUI Interview QuestionsWebservices(or)SoapUI Interview Questions
Webservices(or)SoapUI Interview Questions
 
Learn SoapUI
Learn SoapUILearn SoapUI
Learn SoapUI
 
Angular vs FORWARD
Angular vs FORWARDAngular vs FORWARD
Angular vs FORWARD
 
Web api 2 With MVC 5 With TrainerKrunal
Web api 2 With MVC 5 With TrainerKrunalWeb api 2 With MVC 5 With TrainerKrunal
Web api 2 With MVC 5 With TrainerKrunal
 
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
Behavior-Driven Development and Automation Testing Using Cucumber Framework W...
 
Datasense
DatasenseDatasense
Datasense
 
Testing Web Services - QA or the Highway 2016
Testing Web Services - QA or the Highway 2016Testing Web Services - QA or the Highway 2016
Testing Web Services - QA or the Highway 2016
 

Viewers also liked

Grails Plugins
Grails PluginsGrails Plugins
Grails Plugins
NexThoughts Technologies
 
GORM
GORMGORM
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
NexThoughts Technologies
 
Bootstrap
BootstrapBootstrap
Unit testing
Unit testingUnit testing
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
NexThoughts Technologies
 
Grails Views
Grails ViewsGrails Views
Introduction to Grails
Introduction to GrailsIntroduction to Grails
Introduction to Grails
NexThoughts Technologies
 
Groovy
GroovyGroovy
Groovy intro
Groovy introGroovy intro
Meta Programming in Groovy
Meta Programming in GroovyMeta Programming in Groovy
Meta Programming in Groovy
NexThoughts Technologies
 
Docker
DockerDocker
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
NexThoughts Technologies
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
NexThoughts Technologies
 
Mixpanel
MixpanelMixpanel
Actors model in gpars
Actors model in gparsActors model in gpars
Actors model in gpars
NexThoughts Technologies
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
NexThoughts Technologies
 
Java reflection
Java reflectionJava reflection
Java reflection
NexThoughts Technologies
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
NexThoughts Technologies
 
Grails Controllers
Grails ControllersGrails Controllers
Grails Controllers
NexThoughts Technologies
 

Viewers also liked (20)

Grails Plugins
Grails PluginsGrails Plugins
Grails Plugins
 
GORM
GORMGORM
GORM
 
Config BuildConfig
Config BuildConfigConfig BuildConfig
Config BuildConfig
 
Bootstrap
BootstrapBootstrap
Bootstrap
 
Unit testing
Unit testingUnit testing
Unit testing
 
Linux Introduction
Linux IntroductionLinux Introduction
Linux Introduction
 
Grails Views
Grails ViewsGrails Views
Grails Views
 
Introduction to Grails
Introduction to GrailsIntroduction to Grails
Introduction to Grails
 
Groovy
GroovyGroovy
Groovy
 
Groovy intro
Groovy introGroovy intro
Groovy intro
 
Meta Programming in Groovy
Meta Programming in GroovyMeta Programming in Groovy
Meta Programming in Groovy
 
Docker
DockerDocker
Docker
 
Introduction to mongo db
Introduction to mongo dbIntroduction to mongo db
Introduction to mongo db
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Mixpanel
MixpanelMixpanel
Mixpanel
 
Actors model in gpars
Actors model in gparsActors model in gpars
Actors model in gpars
 
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
Grails Plugins(Console, DB Migration, Asset Pipeline and Remote pagination)
 
Java reflection
Java reflectionJava reflection
Java reflection
 
MetaProgramming with Groovy
MetaProgramming with GroovyMetaProgramming with Groovy
MetaProgramming with Groovy
 
Grails Controllers
Grails ControllersGrails Controllers
Grails Controllers
 

Similar to Grails Services

Grails services
Grails servicesGrails services
Grails services
NexThoughts Technologies
 
Grails services
Grails servicesGrails services
Grails services
Vijay Shukla
 
Siebel best practices
Siebel best practicesSiebel best practices
Siebel best practices
Satish Vemula
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
Mike Willbanks
 
Serverless Computing Model
Serverless Computing ModelServerless Computing Model
Serverless Computing Model
Mohamed Samir
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
Phil Leggetter
 
Phil Green - We're migrating to the cloud - Who needs service management
Phil Green - We're migrating to the cloud - Who needs service managementPhil Green - We're migrating to the cloud - Who needs service management
Phil Green - We're migrating to the cloud - Who needs service management
itSMF UK
 
Чурюканов Вячеслав, “Code simple, but not simpler”
Чурюканов Вячеслав, “Code simple, but not simpler”Чурюканов Вячеслав, “Code simple, but not simpler”
Чурюканов Вячеслав, “Code simple, but not simpler”EPAM Systems
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2divzi1913
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15
Derek Ashmore
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2Long Nguyen
 
Domain Logic Patterns
Domain Logic PatternsDomain Logic Patterns
Domain Logic Patterns
ElifTech
 
DevOps Introduction - Main Concepts Description
DevOps Introduction - Main Concepts DescriptionDevOps Introduction - Main Concepts Description
DevOps Introduction - Main Concepts Description
BrunoOliveira631137
 
Serverless Solutions for developers
Serverless Solutions for developersServerless Solutions for developers
Serverless Solutions for developers
Juan Pablo
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
Steven Smith
 
Cloud-based Test Microservices JavaOne 2014
Cloud-based Test Microservices JavaOne 2014Cloud-based Test Microservices JavaOne 2014
Cloud-based Test Microservices JavaOne 2014
Shelley Lambert
 
OutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modulesOutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modules
Kurt Vandevelde
 
Outsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modulesOutsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modules
Providit
 
Testing for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayTesting for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration Monday
BizTalk360
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
Gal Marder
 

Similar to Grails Services (20)

Grails services
Grails servicesGrails services
Grails services
 
Grails services
Grails servicesGrails services
Grails services
 
Siebel best practices
Siebel best practicesSiebel best practices
Siebel best practices
 
SOA with Zend Framework
SOA with Zend FrameworkSOA with Zend Framework
SOA with Zend Framework
 
Serverless Computing Model
Serverless Computing ModelServerless Computing Model
Serverless Computing Model
 
Patterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 appsPatterns and practices for building enterprise-scale HTML5 apps
Patterns and practices for building enterprise-scale HTML5 apps
 
Phil Green - We're migrating to the cloud - Who needs service management
Phil Green - We're migrating to the cloud - Who needs service managementPhil Green - We're migrating to the cloud - Who needs service management
Phil Green - We're migrating to the cloud - Who needs service management
 
Чурюканов Вячеслав, “Code simple, but not simpler”
Чурюканов Вячеслав, “Code simple, but not simpler”Чурюканов Вячеслав, “Code simple, but not simpler”
Чурюканов Вячеслав, “Code simple, but not simpler”
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15Microservices for java architects it-symposium-2015-09-15
Microservices for java architects it-symposium-2015-09-15
 
Struts 2-overview2
Struts 2-overview2Struts 2-overview2
Struts 2-overview2
 
Domain Logic Patterns
Domain Logic PatternsDomain Logic Patterns
Domain Logic Patterns
 
DevOps Introduction - Main Concepts Description
DevOps Introduction - Main Concepts DescriptionDevOps Introduction - Main Concepts Description
DevOps Introduction - Main Concepts Description
 
Serverless Solutions for developers
Serverless Solutions for developersServerless Solutions for developers
Serverless Solutions for developers
 
Improving the Quality of Existing Software
Improving the Quality of Existing SoftwareImproving the Quality of Existing Software
Improving the Quality of Existing Software
 
Cloud-based Test Microservices JavaOne 2014
Cloud-based Test Microservices JavaOne 2014Cloud-based Test Microservices JavaOne 2014
Cloud-based Test Microservices JavaOne 2014
 
OutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modulesOutSystems community meetup 2018 11 service modules
OutSystems community meetup 2018 11 service modules
 
Outsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modulesOutsystems community meetup 2018 11 service modules
Outsystems community meetup 2018 11 service modules
 
Testing for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration MondayTesting for Logic App Solutions | Integration Monday
Testing for Logic App Solutions | Integration Monday
 
Reactive Micro Services with Java seminar
Reactive Micro Services with Java seminarReactive Micro Services with Java seminar
Reactive Micro Services with Java seminar
 

More from NexThoughts Technologies

Alexa skill
Alexa skillAlexa skill
GraalVM
GraalVMGraalVM
Docker & kubernetes
Docker & kubernetesDocker & kubernetes
Docker & kubernetes
NexThoughts Technologies
 
Apache commons
Apache commonsApache commons
Apache commons
NexThoughts Technologies
 
HazelCast
HazelCastHazelCast
MySQL Pro
MySQL ProMySQL Pro
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
NexThoughts Technologies
 
Swagger
SwaggerSwagger
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
NexThoughts Technologies
 
Arango DB
Arango DBArango DB
Jython
JythonJython
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
NexThoughts Technologies
 
Smart Contract samples
Smart Contract samplesSmart Contract samples
Smart Contract samples
NexThoughts Technologies
 
My Doc of geth
My Doc of gethMy Doc of geth
My Doc of geth
NexThoughts Technologies
 
Geth important commands
Geth important commandsGeth important commands
Geth important commands
NexThoughts Technologies
 
Ethereum genesis
Ethereum genesisEthereum genesis
Ethereum genesis
NexThoughts Technologies
 
Ethereum
EthereumEthereum
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
NexThoughts Technologies
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
NexThoughts Technologies
 
Google authentication
Google authenticationGoogle authentication
Google authentication
NexThoughts Technologies
 

More from NexThoughts Technologies (20)

Alexa skill
Alexa skillAlexa skill
Alexa skill
 
GraalVM
GraalVMGraalVM
GraalVM
 
Docker & kubernetes
Docker & kubernetesDocker & kubernetes
Docker & kubernetes
 
Apache commons
Apache commonsApache commons
Apache commons
 
HazelCast
HazelCastHazelCast
HazelCast
 
MySQL Pro
MySQL ProMySQL Pro
MySQL Pro
 
Microservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & ReduxMicroservice Architecture using Spring Boot with React & Redux
Microservice Architecture using Spring Boot with React & Redux
 
Swagger
SwaggerSwagger
Swagger
 
Solid Principles
Solid PrinciplesSolid Principles
Solid Principles
 
Arango DB
Arango DBArango DB
Arango DB
 
Jython
JythonJython
Jython
 
Introduction to TypeScript
Introduction to TypeScriptIntroduction to TypeScript
Introduction to TypeScript
 
Smart Contract samples
Smart Contract samplesSmart Contract samples
Smart Contract samples
 
My Doc of geth
My Doc of gethMy Doc of geth
My Doc of geth
 
Geth important commands
Geth important commandsGeth important commands
Geth important commands
 
Ethereum genesis
Ethereum genesisEthereum genesis
Ethereum genesis
 
Ethereum
EthereumEthereum
Ethereum
 
Springboot Microservices
Springboot MicroservicesSpringboot Microservices
Springboot Microservices
 
An Introduction to Redux
An Introduction to ReduxAn Introduction to Redux
An Introduction to Redux
 
Google authentication
Google authenticationGoogle authentication
Google authentication
 

Recently uploaded

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
Sri Ambati
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Aggregage
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 

Recently uploaded (20)

GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
GenAISummit 2024 May 28 Sri Ambati Keynote: AGI Belongs to The Community in O...
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Generative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to ProductionGenerative AI Deep Dive: Advancing from Proof of Concept to Production
Generative AI Deep Dive: Advancing from Proof of Concept to Production
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 

Grails Services

  • 2. WHY SERVICES • Image a scenario of a company where employees are assigned tasks based on the nature of their work. There is a employee Popeye who is the team leader so he has different responsibilities such as : • Handle client calls and guide them. • Generate excel sheets with data for analysis. • Manage schedule of team members . • Schedule and look over calls for team members. As you can see Popeye’s work is too hectic and complicated because all the tasks being handled by them are of very different nature , he’s more likely to get stressed out and make mistakes. His errors could cost a lot of money in the long run. Another problem is it's not easy to replace Popeye as he is too involved in a complicated setup. Likewise in software, it is not really a great idea to write a class with different responsibilities, a single class or source file should only be involved in only one nature of task .If there is a lot of things going on, this will only introduce bugs and problems later as the application will be very complicated to maintain.
  • 3. WHY NOT JUST CONTROLLER Consider a controller in Grails .Inside a controller, we can do the following. • Handle routing logic. • Invoke GORM operations to manipulate data in database. • Render text and show it to user. However, it is not advisable that we do all those things inside a controller. Grails allows a developers to do all these things together for flexibility, but it should be avoided. The real purpose of a controller is to deal with the routing login which means : • Receive requests from user. • Invoke the appropriate business login(services) • Invoke the view to display result
  • 4. DON’T REPEAT YOURSELF(DRY) These days most of the technologies are following the DRY concept which follows a strict practice of not having to duplicate code, using a service layer is you could reuse a business logic in multiple places without code duplication. Having a single copy of a particular business logic will make a project shorter (in terms of lines of codes) and easier to maintain. Changing the business logic will just require a change in only one particular place.
  • 5. CREATING A SERVICE - To create a service , you can use create-service command from the root folder of your application.Ex. grails create-service com.test.Test The above command would create a TestService in com/test directory path . - Or you can also create service from your ide. - Service created would have the following content package com.test class TestService{ def serviceMethod(){ } } - You can go on adding as many method in the services having same nature of tasks.
  • 6. INJECTING A SERVICE • To use service methods , you would need to inject the service . • Services can be injected in a controller , domain , tag libs,Bootstrap or another service. • To inject a service in a controller package com.test class TestController{ def testService def saveData(){ testService.serviceMethod() } }
  • 7. TRANSACTION MANAGEMENT • Transaction is a very important concept. Hope you are well aware of ACID(Atomicity, Consistency, Isolation, Durability) properties . • Usually we wish certain sequence of database changes to be successful. If not possible we want no operation to happen at all. • Imagine a code that deducts money from one account (accountFrom.balance = accountFrom.balance - amount), and adds money to another account (accountTo.balance = accountTo.balance + amount). Imagine if something happened (an Exception) after deducting from the source account and the destination account was not updated. Money will be lost and not accounted for. For this type of codes, we want an "all or nothing" behavior. This concept is also called atomicity. • Since Grails supports transactions, it automatically do these things to us when we declare a service to be transactional: • If all db operations are successful, reflect the changes to the database (this is also called commit) • If one db operation result in exception, return to the original state and forget/undo all the previous operations (this is also called rollback) • By default all services are transactional, if you don’t want transactional behavior of the service you can get rid of it by class TestService(){ static transactional=false }
  • 8. SCOPE • By default, access to service methods is not synchronized, so nothing prevents concurrent execution of those methods. In fact, because the service is a singleton and may be used concurrently, you should be very careful about storing state in a service. • You You can change this behavior by placing a service in a particular scope. The supported scopes are: • prototype - A new service is created every time it is injected into another class • request - A new service will be created per request • flash - A new service will be created for the current and next request only • flow - In web flows the service will exist for the scope of the flow • conversation - In web flows the service will exist for the scope of the conversation. ie a root flow and its sub flows • session - A service is created for the scope of a user session • singleton (default) - Only one instance of the service ever exists • To enable one of the scopes, add a static scope property to your class whose value is one of the above. Ex static scope=“session”