SlideShare a Scribd company logo
Cleaning up Sitecore Controllers
/ug/ch/
The Origin Story
● Introduction of NitroNet for Sitecore in our projects
● The ViewModel becomes the contract between frontend
and backend
● We need a concept to embrace the building of the
model
Quick Recap on NitroNet
NitroNet for Sitecore brings at least two major changes to
your development workflow
● No more razor views
○ All views are build with handlebars
● Controller renderings only
○ View renderings are not supported by NitroNet for Sitecore,
although they can still be used in a hybrid scenario
Introducing the Model Factory
The Model Builder Interfaces
A Model Builder Interface in Detail
Example of a Model Builder
The DefaultModelFactory
A cleanish Sitecore Controller
When Controllers have ambitions...
All the controllers started to look the same, so we introduced
three base classes for the most common patterns
● ControllerBase<TViewModel>
● ContextControllerBase<TDataModel,TViewModel>
● DatasourceControllerBase<TDataModel,TViewModel>
A clean Sitecore Controller
Stay DRY with Nested Model Builders
There might be components that are reused as atoms in
your code base like…
● Links
● Images
● Icons
● Many more...
Example of a Nested Model Builder
Add Model Validation to the mix
Add Model Validation to the mix
The ValidationService
Example of a Model Validator
Summary of the Features
● IModelFactory as single point of entry
● Single purpose model builders
● Experience Editor support with EditingMocks
● Model Validation for inputs and outputs
● Simple Form support (attribute based)
Pros and Cons
Pros
● Decouple model building
● Reusable model builders
● Small (single purpose)
● Integrated validation
● Works with GlassMapper
● Works with Synthesis
● Works with SXA
Cons
● Another level of
abstraction
● A potential complexity
with many levels of
nesting
Additional Resources
● Blog Posts
○ https://www.studert.com/cleaning-up-sitecore-controllers/
○ https://www.studert.com/stay-dry-with-nested-model-builders/
○ https://www.studert.com/what-happens-when-clean-sitecore-co
ntrollers-have-ambitions/
● Code will be available on GitHub
○ https://github.com/unic
About me
● Tobias Studer
○ Senior Tschipuperi @ Unic
○ Sitecore MVP since 2016
● Find me here
○ Twitter: @studert
○ GitHub: https://github.com/studert
○ Blog: https://www.studert.com/
Thank you and check out...
Women of Sitecore
Building inclusion and diversity through community
https://www.womenofsitecore.com/
/ug/ch/

More Related Content

PPTX
Getting Started With AngularJS
PPTX
Presentation on angular 5
PPTX
Introduction to React
PDF
KDE 4.1 Plasma widgets
PDF
Openflexo's infrastructure - exhibitor - @models2012
PPTX
React native introduction (Mobile Warsaw)
PPTX
Aplicaciones en tiempo real con ReactJS y SignalR Core
Getting Started With AngularJS
Presentation on angular 5
Introduction to React
KDE 4.1 Plasma widgets
Openflexo's infrastructure - exhibitor - @models2012
React native introduction (Mobile Warsaw)
Aplicaciones en tiempo real con ReactJS y SignalR Core

Similar to Cleaning up Sitecore Controllers (20)

PPTX
Hanselman lipton asp_connections_ams304_mvc
PPTX
Sitecore mvc
PDF
[JogjaJS] Single Page Application nganggo Angular.js
PDF
FrontEnd.pdf
PPTX
Anypoint Code Builder June Release Overview, ASync API and Einstein Features....
PPTX
Foster - Getting started with Angular
PDF
Rise with angular
PDF
Angular, the New Angular JS
PPTX
Building APIs with Mule and Spring Boot
PDF
Feature Development with jQuery
PDF
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
PDF
Cameo Workbench
PDF
You Can Work on the Web Patform! (GOSIM 2023)
PDF
ODP
Contributions: what they are and how to find them
PPTX
Web worker in your angular application
PDF
Servo: A Web View From Somewhere Else
PDF
JAB14 Honey I shrunk the code
PPTX
SUG Bangalore - Kick Off Session
PPTX
Iteria lowcode 2022-01-10
Hanselman lipton asp_connections_ams304_mvc
Sitecore mvc
[JogjaJS] Single Page Application nganggo Angular.js
FrontEnd.pdf
Anypoint Code Builder June Release Overview, ASync API and Einstein Features....
Foster - Getting started with Angular
Rise with angular
Angular, the New Angular JS
Building APIs with Mule and Spring Boot
Feature Development with jQuery
RESTful Machine Learning with Flask and TensorFlow Serving - Carlo Mazzaferro
Cameo Workbench
You Can Work on the Web Patform! (GOSIM 2023)
Contributions: what they are and how to find them
Web worker in your angular application
Servo: A Web View From Somewhere Else
JAB14 Honey I shrunk the code
SUG Bangalore - Kick Off Session
Iteria lowcode 2022-01-10
Ad

Recently uploaded (20)

PPTX
Tartificialntelligence_presentation.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Encapsulation theory and applications.pdf
PDF
project resource management chapter-09.pdf
PPTX
A Presentation on Artificial Intelligence
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
August Patch Tuesday
PPTX
TLE Review Electricity (Electricity).pptx
PPTX
OMC Textile Division Presentation 2021.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Hybrid model detection and classification of lung cancer
PDF
Accuracy of neural networks in brain wave diagnosis of schizophrenia
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Tartificialntelligence_presentation.pptx
Unlocking AI with Model Context Protocol (MCP)
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Chapter 5: Probability Theory and Statistics
1 - Historical Antecedents, Social Consideration.pdf
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Encapsulation theory and applications.pdf
project resource management chapter-09.pdf
A Presentation on Artificial Intelligence
Digital-Transformation-Roadmap-for-Companies.pptx
A comparative analysis of optical character recognition models for extracting...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
August Patch Tuesday
TLE Review Electricity (Electricity).pptx
OMC Textile Division Presentation 2021.pptx
Zenith AI: Advanced Artificial Intelligence
Hybrid model detection and classification of lung cancer
Accuracy of neural networks in brain wave diagnosis of schizophrenia
Hindi spoken digit analysis for native and non-native speakers
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Ad

Cleaning up Sitecore Controllers

  • 1. Cleaning up Sitecore Controllers /ug/ch/
  • 2. The Origin Story ● Introduction of NitroNet for Sitecore in our projects ● The ViewModel becomes the contract between frontend and backend ● We need a concept to embrace the building of the model
  • 3. Quick Recap on NitroNet NitroNet for Sitecore brings at least two major changes to your development workflow ● No more razor views ○ All views are build with handlebars ● Controller renderings only ○ View renderings are not supported by NitroNet for Sitecore, although they can still be used in a hybrid scenario
  • 5. The Model Builder Interfaces
  • 6. A Model Builder Interface in Detail
  • 7. Example of a Model Builder
  • 9. A cleanish Sitecore Controller
  • 10. When Controllers have ambitions... All the controllers started to look the same, so we introduced three base classes for the most common patterns ● ControllerBase<TViewModel> ● ContextControllerBase<TDataModel,TViewModel> ● DatasourceControllerBase<TDataModel,TViewModel>
  • 11. A clean Sitecore Controller
  • 12. Stay DRY with Nested Model Builders There might be components that are reused as atoms in your code base like… ● Links ● Images ● Icons ● Many more...
  • 13. Example of a Nested Model Builder
  • 14. Add Model Validation to the mix
  • 15. Add Model Validation to the mix
  • 17. Example of a Model Validator
  • 18. Summary of the Features ● IModelFactory as single point of entry ● Single purpose model builders ● Experience Editor support with EditingMocks ● Model Validation for inputs and outputs ● Simple Form support (attribute based)
  • 19. Pros and Cons Pros ● Decouple model building ● Reusable model builders ● Small (single purpose) ● Integrated validation ● Works with GlassMapper ● Works with Synthesis ● Works with SXA Cons ● Another level of abstraction ● A potential complexity with many levels of nesting
  • 20. Additional Resources ● Blog Posts ○ https://www.studert.com/cleaning-up-sitecore-controllers/ ○ https://www.studert.com/stay-dry-with-nested-model-builders/ ○ https://www.studert.com/what-happens-when-clean-sitecore-co ntrollers-have-ambitions/ ● Code will be available on GitHub ○ https://github.com/unic
  • 21. About me ● Tobias Studer ○ Senior Tschipuperi @ Unic ○ Sitecore MVP since 2016 ● Find me here ○ Twitter: @studert ○ GitHub: https://github.com/studert ○ Blog: https://www.studert.com/
  • 22. Thank you and check out... Women of Sitecore Building inclusion and diversity through community https://www.womenofsitecore.com/ /ug/ch/