Table of Contents

Depedency Injection in 2sxc and EAV

Dependency Injection is a way to structure applications and to get Services or Helpers in your code.

👉 We suggest you read the introduction to Dependency Injection

How Can I Use Dependency Injection in Razor?

Previously this was reserved for internal use. Starting in 2sxc v11.11 all Razor classes have a command called GetService. This is how your code would get a service:

@inherits Custom.Hybrid.Razor14
@Kit.Page.AddOpenGraph("video", "https://2sxc.org/videos/intro.mp4");

👉 Read more about GetService in the docs or in the GetService API.

How Can I Use Dependency Injection in WebAPIs?

Just like with with Razor, 2sxc 11.11 added the same GetService to all WebAPIs.

How Can I Use Dependency Injection in Dnn Modules and Skins

👉 Dependency Injection in Dnn Skins and Modules

How Can I Use Dependency Injection in Oqtane

👉 Dependency Injection in Oqtane

Services My Code May Need

You can get just about anything from 2sxc. The most common services you'll request as of 2sxc 12 are in the ToSic.Sxc.Services namespace.

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