Namespace ToSic.Sxc.Services
The Services are the most common helpers / tools used in Razor and WebAPI C#.
Quick Use with @Kit.SomeServiceName
Most services are available on the Kit
object on your Razor or WebApi file.
This requires the use of v14 base classes, such as Razor14
.
Manual Use with GetService<T>
You will usually get a service using the GetService<T>()
method like this:
@using ToSic.Sxc.Services;
@{
var pageSvc = Sxc.GetService<IPageService>();
}
Read more about GetService<T>() or about GetService<T> in general.
To use GetService in a DNN Theme/Skin/Module, check out GetScopedService<T>() and read it in the release blog.
Namespaces
Classes
- DnnExtensions
Provides extension methods for DNN Skins (Themes) and Modules. It only exists on the Dnn platform, not on Oqtane.
- ServiceKit14
Default ServiceKit for 2sxc v14.
- ServiceKit16
Default ServiceKit for 2sxc v14.
- ServiceKitLight16
Lightweight ServiceKit for 2sxc v15. It's primarily used in dynamic code which runs standalone, without a module context.
Example: Custom DataSources can run anywhere without actually being inside a module or content-block. In such scenarios, certain services like the IPageService would not be able to perform any real work.
Interfaces
- IAdamService
WIP - Adam Service for additional ADAM operations such as retrieving a single file
- ICacheService
Experimental! Cache service to help your code cache data.
It does quite a bit of magic, for example:
- scope the cache to the current App, so a key "data" will not bleed to other apps
- change the key when the data is for the current user only
- ...and more.
It's not yet fully documented.
- IConvertService
Conversion helper for things which are very common in web-code like Razor and WebAPIs. It's mainly a safe conversion from anything to a target-type.
Some special things it does:
- Strings like "4.2" reliably get converted to int 4 which would otherwise return 0
- Numbers like 42 reliably converts to bool true which would otherwise return false
- Numbers like 42.5 reliably convert to strings "42.5" instead of "42,5" in certain cultures
- IConvertService16
Conversion helper for things which are very common in web-code like Razor and WebAPIs. It's mainly a safe conversion from anything to a target-type.
Some special things it does:
- Strings like "4.2" reliably get converted to int 4 which would otherwise return 0
- Numbers like 42 reliably converts to bool true which would otherwise return false
- Numbers like 42.5 reliably convert to strings "42.5" instead of "42,5" in certain cultures
- IDataService
Services to create DataSources in Razor as well as external (skin) use.
- IDynamicCodeService
This is a service to give you DynamicCode outside of 2sxc.
Use this to access 2sxc data from a Theme, a
.ascx
WebControl or anywhere else.
- IEditService
Contains status and commands to configure the in-page editing system.
You will never create this yourself, as get this automatically in Razor or WebAPIs on an object called
Edit
.
- IFeaturesService
Features lets your code find out what system features are currently enabled/disabled in the environment. It's important to detect if the admin must activate certain features to let your code do it's work.
- IImageService
Service to help create responsive
img
andpicture
tags the best possible way.
- IJsonService
Service to serialize/restore JSON. Get it using GetService < T >
It works for 2sxc/EAV data but can be used for any data which can be serialized/deserialized. Since it's a data-operation, we keep it in this namespace, even if most other things in this namespace are 2sxc-data objects.
Important This is simple object-string conversion. It doesn't change entity objects to be serializable. For that you should use the IConvertToEavLight which returns an object that can then be serialized.
- IKeyService
WIP 16.04
- ILinkService
Helpers to create links to
- Pages
- APIs
- Images
As well as create base-tag links (important for SPAs)
You will never create this yourself, as get this automatically in Razor or WebAPIs on an object called
Link
.
- IMailService
Service to send mail messages cross-platform.
Get this service in Razor or WebApi using e.g. GetService
- IPageService
Make changes to the page - usually from Razor.
- IRenderService
Block-Rendering system. It's responsible for taking a Block and delivering HTML for the output.
It's used for InnerContent, so that Razor-Code can easily render additional content blocks.
See also Inner Content (Content Within Other Content)
- ISecureDataService
Helper to work with secure / encrypted data.
- ISystemLogService
System-Log Service to add messages to the global log in any platform Dnn/Oqtane
- ITemplateService
Service to help parse token-based templates.
- IToolbarService
Special helper to generate edit toolbars in the front-end. It's especially useful custom and/or complex rules like Metadata-buttons.