SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK
-
Upload
michael-robbins -
Category
Technology
-
view
81 -
download
0
Transcript of SUGCON 2015 : Sitecore as a Content Repository Using Entity Service And SPEAK
Sitecore User Group Conference 2015 1
Sitecore as a content repository using Entity Service,
SPEAK
Mike Robbins MVP
Kagool
@Sobek1985
Sitecore User Group Conference 2015 2
What is Entity Service?
Sitecore.Service.Client
Part of Sitecore.Services.Client providing ASP.NET Web API based web services.
Provides a framework for creating and extending web services using scaffolding.
Framework for both the server and client side.
Contains two web services
Item Service
Entity Service
Entity Service Configuration
• Sitecore.Services.Client.config include file configures the services.
• Security access.
• Enable /disable anonymous access.
• Add Authorisation filters.
• Routing for services.
• Pipelines
• Any changes reflect across all services within SSC.
Entity
• Define the business entity (model) to expose via the web service.
• Must implement the Sitecore.Services.Core.Model.EntityIdentity base
class.
• Decorate properties with .net validation attributes. (Required, RegEx. Etc)
• Support for adding custom client side validation to properties.
Repository
• Implement the
Sitecore.Services.Core.IRepository<Entity> interface.
• Repository pattern scaffolding is added by the interface.
• Provide the business logic for each of the functions.
Controller
• All functionality of the service is derived from the repository.
• Decorate the controller with [ServicesController]
• Implement the EntityService<Entity> base class.
• The service is flexible, easily extended with additional actions.
• Access to the controller can be restricted by using standard .net
MVC Authorisation Filters.
SSC Demo App
Demo – Model /Repository/Controller/IoC
Consuming The Service
• There are three ways to consume a SSC service
1. Calling the Rest API directly
2. Consuming the service using the JavaScript API.
3. Using SPEAK components.
Controller routing
http://HostName/sitecore/api/ssc/namespace-to-controller/controller
Sitecore User Group Conference 2015 11
JavaScript API
JavaScript API
• Library to marshal calls between JavaScript and controller.
• Consume the service in a consistent way.
• Reference the JavaScript library for Entity Service.
"/sitecore/shell/client/Services/Assets/lib/entityservice.js"
var awesomeService = new entityService
({url: "/sitecore/api/ssc/MikeRobbins-Demo-controllers/Brochure“});
Sitecore User Group Conference 2015 13
JavaScript API
• Auto mapping between POCO objects and JavaScript
• Provides validation, and loads in custom validators defined in
the entity.
• fetchEntities()
• fetchEntity(ItemId)
• destroy()
• save()• create(brochureJson)
Demo – Create SPEAK PageCode
Sitecore User Group Conference 2015 15
Extending Entity Service
Extending Entity Service – Custom Actions
• The controller can be extended with additional actions.
• Standard Web API actions and attributes.
• The repository can be extended with additional functionality.
• Currently not available via the JavaScript API
• Default SSC routing
sitecore/api/ssc/Namespace-to-Controller/{controller}/{ID}/{action}
Sitecore User Group Conference 2015 17
Extending Validation
• Based on standard .net DataAnnotations
• Provide server-side validation for the type and a client-
side validation script.
• JavaScript validation script provided in meta data of
the service.
Sitecore User Group Conference 2015 18
Validation / Testing
• Unit.js for validating data returns from the service and
unit testing.
Entity.should.be.an.instanceOf( EntityService.Entity );
Entity.isNew.should.be.false;
Entity.should.have.a.property(“Title");
Sitecore User Group Conference 2015 19
Middleware
• Sits between the server side and promise callback.
• Inject client side logic into the promise before the
result is returned. Update or append to model
Questions?
Entity Service Blog Posts
http://mikerobbins.co.uk/tag/ssc/
Entity Service Demo Application:
https://github.com/sobek1985/Seshat
https://github.com/sobek1985/EntityServiceDemo
Twitter:@Sobek1985
Sitecore User Group Conference 2015 21
Thank you