Deliver superior customer experiences with an AI-driven platform for creating and deploying cognitive chatbots
Deliver Awesome UI with the most complete toolboxes for .NET, Web and Mobile development
Automate UI, load and performance testing for web, desktop and mobile
A complete cloud platform for an app or your entire digital business
Detect and predict anomalies by automating machine learning to achieve higher asset uptime and maximized yield
Automate decision processes with a no-code business rules engine
Optimize data integration with high-performance connectivity
Connect to any cloud or on-premises data source using a standard interface
Build engaging multi-channel web and digital experiences with intuitive web content management
Personalize and optimize the customer experience across digital touchpoints
Build, protect and deploy apps across any platform and mobile device
Rapidly develop, manage and deploy business apps, delivered as SaaS in the cloud
The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.
The series Comparing Sitefinity 3.x to 4 Beta continues with a quick look a the new Fluent API. This is an incredible new addition to the Sitefinity platform, opening an entire new world for developers to accomplish new and exciting tasks and projects.
I had hoped to put together a detailed code walkthrough with tons of examples. However, it turns out a lot if this is already out there! The second half of the Telerik webinar on Sitefinity 4.0 gives a great introduction to the Fluent API by Ivan Osmak, including a few live examples of it in action.
In addition, Falafel Software has also put together not only blog post comparing the Sitefinity APIs, but a companion video as well.
Finally, there is an excellent Fluent API Overview in the Sitefinity 4 Beta Documentation. This documentation includes several complete code examples detailing everything from creating pages to creating your own custom data types (more on this later).
If you're interested in learning more about the Fluent model, take a look at the Fluent Interface and the related Facade Pattern articles on Wikipedia.
Before we continue it's important to point out that the Fluent API is NOT replacing the existing 3.x pattern of using Content Managers. The Content Managers are still available for use, so you can continue to leverage your existing skills from 3.x for accessing, importing, or managing Sitefinity content.
However, the Fluent API IS likely to offer developers an improved experience by simplifying and abstracting away a lot of the boilerplate code needed to develop with the previous model of Content Managers. Many of the tasks involved with managing Sitefinity content will be simplified greatly by using the Fluent API, as we'll see in a quick example later on.
Even if you encounter a custom, complex scenario that isn't yet natively supported in the Fluent API, the Content Managers are still available to you for complete control over your code. This is, once again, another fine example of how Sitefinity continues to combine new features without sacrificing compatibility and flexibility.
Another benefit of this API is the use of Facades. Previously, when developing Sitefinity addons or plugins, you had to program directly against a versioned DLL that corresponded to your current Sitefinity version. However with the new Facade pattern in Sitefinity 4, you now develop with a version-agnostic facade. This means you should no longer require multiple projects to support different versions of Sitefinity; they all support the same facades!
This article wouldn't be complete without at least a quick example comparing the Fluent API to the Content Managers. Here is an example taken from the Sitefinity 4 documentation on creating a blog post:
using (var fluent = App.WorkWith())
Blog blog = fluent.Blogs().Where(b => b.Title == "Sitefinity developers blog").Get().First();
//you should have a blog with that name
//so we can create a post inside
p.Parent = blog;
p.Title = "Blog post in MyBlog";
p.Content = "Here goes my content";
p.PublicationDate = DateTime.Now;
p.ExpirationDate = DateTime.Now.AddDays(3);
As you can see, the code is very straightforward and almost self-documenting. You retrieve the Blogs facade from an instance of the fluent interface, then use chained methods to create and publish a new post.
Comparing it to how it would be done with a Blog Content Manager, you can see that, although they basically perform the same actions, the fluent interface is much more natural:
// create new instance of BlogManager
Telerik.Blogs.BlogManager blogManager = new Telerik.Blogs.BlogManager();
// get all blogs
IList listOfAllBlogs = blogManager.GetBlogs();
if (listOfAllBlogs.Count > 0)
// get the first blog item
Telerik.Blogs.IBlog firstBlog = blogManager.GetBlog(((Telerik.Blogs.IBlog)listOfAllBlogs).ID);
// create a blog post by calling the CreateContent method of the
// ContentManager class through the BlogManager class
Telerik.Cms.Engine.IContent postContent = blogManager.Content.CreateContent("text/html");
// set the parent of the post item to be firstBlog
postContent.ParentID = firstBlog.ID;
// save the Content property value and the Title meta key
postContent.Content = "Here goes my content";
postContent.SetMetaData("Title", "Blog post in MyBlog");
//save the Content item through the BlogManager
The Fluent API is an excellent new feature that I'm confident all current Sitefinity developers will appreciate. Developing against facades ensures that developers can focus on functionality, ensured that compatibility will automatically be provided by the Framework.
Ultimately, as always, Sitefinity still gives you the choice to decide which format works better for you and your development needs.
View all posts from The Progress Guys on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Copyright © 2018 Progress Software Corporation and/or its subsidiaries or affiliates.
All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.