Table of Contents

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+).

you are here (click to zoom) - discover the stack

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:

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:

  1. It requires that you use Dnn 9.4+
  2. It also requires 2sxc v13 as that now fully integrations with the Dnn Service Provider
  3. 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:

  1. If you're writing Blazor code then most services only exist as a proxy, the real work happens on the backend
  2. 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

  1. 2sxc introduced Dependency Injection 1.1 in v9 (May 2017)
  2. Integrated with Oqtane DI in v12 (May 2021)
  3. GetService<T> pattern introduced for Razor/C# in v12 (May 2021)
  4. Integrated with Oqtane DI in v12 (May. 2021)
  5. Upgraded to Dependency Injection 2.1 in v13 (Dec. 2021)
  6. Integrated with Dnn DI in v13 (Dec. 2021)
  7. Created ServiceKits for v14 (June 2022)
  8. Added ServiceKitLight for custom DataSources in 2sxc 15
  9. Added ServiceKit16 for 2sxc 16