C# Services
Tip
2sxc has a rich set of Services which are Helpers to easily get things done.
You can also create your own services as DLLs (v12+) or in your App (v17.03+).
ServiceKits (new in v14)
V14 introduces the concept of ServiceKits.
They give you access to all common services directly on the Kit
object.
Tip
The service kit provides more than 10 commonly used services.
Some popular services include:
- Toolbar Service to build toolbars for the editor
- Page Service to get/set page properties, run scripts, load resources and more
More Services
👉🏽 See More Services
How Services Work
Technically a service is just a .net object which does stuff for you. They are provided through Dependency Injection.
You can get Services in your C# code like this:
using ToSic.Sxc.Services;
var page = GetService<IPageService>();
Internally services may require additional information to work - like the current Page it's on etc. This happens almost by magic thanks to Dependency Injection. If this is new to you, you should read up on it.
Integration with Dnn Services
Dnn is still new to Dependency Injection. Because of this, there are some limitations if you want to get a Dnn service. For example:
- It requires that you use Dnn 9.4+
- It also requires 2sxc v13 as that now fully integrations with the Dnn Service Provider
- Not all Dnn Objects exist as services. You'll need to browse Dnn code to figure this out.
Integration with Oqtane Services
Oqtane started as a .net Core project so Dependency Injection is in it's DNA.
Anything Oqtane has can be requested as a Service, but there are some caveats:
- If you're writing Blazor code then most services only exist as a proxy, the real work happens on the backend
- If you're writing server-side code then most services are available, but the name / signature may be a bit different than the Blazor service
Create your own Service
👉 Check out Create Custom C# Services
History of Dependency Injection in 2sxc
- 2sxc introduced Dependency Injection 1.1 in v9 (May 2017)
- Integrated with Oqtane DI in v12 (May 2021)
GetService<T>
pattern introduced for Razor/C# in v12 (May 2021)- Integrated with Oqtane DI in v12 (May. 2021)
- Upgraded to Dependency Injection 2.1 in v13 (Dec. 2021)
- Integrated with Dnn DI in v13 (Dec. 2021)
- Created ServiceKits for v14 (June 2022)
- Added ServiceKitLight for custom DataSources in 2sxc 15
- Added ServiceKit16 for 2sxc 16