DEV Community

Cover image for Xperience Community: Essentials
Victor Hugo Garcia
Victor Hugo Garcia

Posted on

Xperience Community: Essentials

If you work with Xperience by Kentico, you know how much repetitive code can pile up across projects. From text manipulation and encryption to URL handling and localization, the small things add up fast. That’s why the Xperience Community: Essentials package was created — a lightweight, yet powerful collection of helpers, utilities, and extensions designed to make your life easier and your codebase cleaner.

With this NuGet package, you can spend less time rewriting boilerplate and more time focusing on the actual business logic of your application.


Implementation

Getting started is incredibly easy. You can add the package directly to your Xperience project via the .NET CLI:

dotnet add package XperienceCommunity.Essentials
Enter fullscreen mode Exit fullscreen mode

Once installed, initialize the configuration helper in your Program.cs file:

ConfigurationHelper.Initialize(builder.Configuration);
Enter fullscreen mode Exit fullscreen mode

This step activates configuration-dependent features such as AES encryption and other utilities that rely on your app's configuration settings.

If you plan to use encryption helpers, you’ll also need to define a section in your appsettings.json:

{
  "XperienceCommunityEssentials": {
    "AesSecureKey": "your-base64-key"
  }
}
Enter fullscreen mode Exit fullscreen mode

That’s it! You’re now ready to start using the wide range of extensions the package provides.


Key Features

AES Encryption Helper

Protect sensitive information with simple encryption and decryption methods. Just configure your AES key once, and you can easily encrypt or decrypt strings throughout your project.

Text Helper Extensions

Tackle common text operations effortlessly. From truncating and Base64 encoding to cleaning HTML and generating random IDs, these helpers eliminate repetitive code and make string handling a breeze.

Collection Extensions

One of the most powerful parts of this library is the Collection Extensions, especially when working with Xperience asset collections, related items, or structured content.

When you’re dealing with lists of assets, pages, or objects, you often need to check if data exists, access nested properties safely, or retrieve default values — all without endless null-checks or verbose LINQ.

These extensions make your code much cleaner and more expressive. For example:

// Safely get the first matching asset name
string name = assetCollection.GetFirstOrEmpty(a => a.AssetFile.Metadata.Name);

// Get the first asset URL or an empty string if not available
string url = assetCollection.GetFirstOrEmpty(a => a.AssetFile.Url);

// Retrieve a default value safely from complex collections
int count = assetCollection.GetFirstOrDefault(a => a.SomeIntProperty, 0);

// Check if two collections have any matching elements
bool hasMatch = sourceList.ContainsAny(targetList);
Enter fullscreen mode Exit fullscreen mode

These helpers are especially handy for handling content hub assets, and custom structured data. Instead of defensive coding everywhere, you can write elegant one-liners that are both safe and maintainable.

Localization Extensions

Improve your localization workflow with built-in fallbacks. Never worry about missing translations again — just define a default value that will be displayed when a key isn’t found.

URL Helpers

Easily manipulate URLs within Xperience. Convert relative URLs to absolute ones, trim paths, or safely handle URL conversions in your page components.

Enum Dropdown Provider

Populate dropdowns dynamically using enums — perfect for admin UI components and form fields. With a few lines of code, your enums become user-friendly selection options.


Example Usage

Here are a few quick examples that show how convenient these helpers can be:

// Encrypt and decrypt text
string encrypted = EncryptionHelper.EncryptAes("sensitive info");
string decrypted = EncryptionHelper.DecryptAes(encrypted);

// Clean HTML
string clean = htmlContent.CleanHtml();

// Generate random ID
string id = TextHelper.GenerateId(12);

// Safe property access
string name = assetCollection.GetFirstOrEmpty(a => a.AssetFile.Metadata.Name);

// Localized text with fallback
string text = localizer.GetStringOrDefault("Welcome", "Welcome to our site!");
Enter fullscreen mode Exit fullscreen mode

These examples show how XperienceCommunity.Essentials simplifies daily development and improves code consistency across your projects.


Conclusion

The Xperience Community: Essentials package was built to save developers time and help maintain cleaner, more maintainable codebases. It consolidates common functionality that nearly every Xperience project needs into a single, well-documented library.


Follow me on Social:

Top comments (0)