Table of Contents

Dependency Injection in Dnn Skins and Modules

Since Dnn 9.4, Dependency Injection is built in. It's still fairly basic, so there are some hoops to jump through, but for now it's the recommended way to work with this.

Important

You need Dnn 9.4+ for these examples to work.

2sxc 13 will only support this form of providing services outside of 2sxc, so if you need this, make sure you upgrade.

What works, and what doesn't

  1. All 2sxc services can be accessed via DI from Dnn code that support DI - such as themes and modules
  2. 2sxc has a full API to provide rendered Blocks, Services and Data to Dnn code
  3. Some - but only a few - of Dnn Services are available on DI

How Can I Get Dnn Objects using Dependency Injection?

As of Dnn 9.10 the answer is mostly no 😶. Dnn is simply not there yet. Work-in-progress.

The documentation is almost non-existant, so if you want to try using Dnn objects, you'll need to dig through Dnn code to get this to fly.

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