Sitecore Service Client ServicesApiController

With Sitecore 7.5 and now Sitecore 8, Sitecore.Services.Client (SSC) was introduced. This has given us a flexible and powerful framework for created Web API based rest services in Sitecore (See my introduction into Entity Service (part of Sitecore.Services.Client))

Entity Service is powerful, offering the repository pattern to implement functionality such as FindAll, FindByID, Create, Delete and Update for a given Entity (Model).

However, what happens if you want to create a completely bespoke Web API controller and don’t need any of the functionality from the repository of Entity Service. Up until now we have done something similar to my blog article here where we extend some Sitecore pipelines to register custom routes and abort those.

ServicesApiController

With Sitecore.Services.Client we now have another option available to us, ServicesApiController. ServicesApiController is a abstract class that sits on-top of the .NET ApiController, offering the same core functionality as the start controller. ServicesApiController sits within Sitecore.Services.Core so you need to make sure you include the DLL in your solution.

The advantage of using ServicesApiController means we get all the security benefits and filters of Sitecore.Service.Client Anders Laub has a blog post talking about this.

ServicesController

If we don’t want to extend the Sitecore pipelines to register routes for our custom controller, we can use another part of Sitecore.Services.Client – ServicesController. ServicesController is a attribute we can use to decorate our controllers, this then includes the controller is Sitecore.Services.Client routing.

Decorating our controllers with this attribute means we no longer need to extend any of the Sitecore pipelines to configure the routing. Our custom controller will now use the Sitecore.Services.Client style routing my default.

Eg. //HostName/sitecore/api/ssc/namespace-to-controller/{controller}/{id}/action.

Below is an example of a custom controller using ServiceApiController together with ServicesController.

Here is the output from a web request to the controller action.

JSON returned
JSON returned

Sitecore Entity Service SSC – IoC Configuration

Further into my series on Sitecore Entity Service within Sitecore.Services.Client, in this post I’ll be look into setting up an IoC container (Structure Map in this post) for Entity Service. 

In the below example of the Entity Service services controller we have an overloaded constructor creating a concrete instance of our repository. However moving towards a DI approach we want to remove the coupling to the repository and inject the dependency in instead. Continue reading

Sitecore Glass Attribute Helper Methods 

When using Sitecore Glass’s helpers to render content in a experience editor compatible way, it is possible to add a NameValue collection to specify attributes to be appended to the HTML element. http://stackoverflow.com/questions/19587981/how-to-render-link-with-css-class-with-sitecore-glass-mapper Continue reading

Sitecore ContentSearch Language Based Search

Just a quick blog on using Sitecore content search within multilingual sites.

A very basic way of achieving a multilingual search,  i’ve used in the past involves building a query to filter on the language from the Sitecore.Context.Language. This method is explained in a previous tweet from Jamie Little and a blog post, however a comment from Stephen Pope shed more detail on content search, where you can actually pass in a culture into the content search.
Continue reading