Table of Contents

Dnn Platform API Guide

This section is about special topics / APIs when programming with 2sxc in DNN.

👉🏽 For the general platform topics such as installation, see the Dnn Platform Guide.

Sometimes you want to leverage 2sxc to create a solution, provide data input etc. but want to output or re-use the data in your own Module, Skin, Script or something else. This is easy to do.

Important

We massively improved this in 2sxc 13 which integrates with Dnn 9 Dependency Injection. These examples require Dnn 9.5+ and 2sxc 14+

Dnn Platform API Basics

  1. In general, everything in 2sxc is the same for all platforms.
  2. For Dnn it's important to realize that its based on some older Frameworks
    1. .net Framework 4.7.2 as of DNN 9.6.1, or .net Framework 4.8 for the latest DNN
    2. Razor uses the fairly old MVC 3
    3. C# is also an older version, we believe ca. 6.0. For example, you cannot use var x = x?.y?.z because it's not supported in this version.
  3. Dependency Injection is still fairly new in DNN
    1. not all DNN services are available in dependency injection
    2. not all DNN controls can use dependency injection
    3. certain uses of dependency injection cause some surprises

With this in mind, let's see how we can solve some common challenges.

Use Dnn Objects and Services in 2sxc

  1. General user, site (portal) and similar information
    1. Just use the CmsContext objects - eg. CmsContext.User or CmsContext.Site
    2. This is the same across platforms, so code written like this will also run on Oqtane
  2. Access really specific DNN objects
    1. Use the normal DNN API which is not dependency injection based.
    2. For most objects you will use the old static API to get the Current objects. For example, to get the current portal, use PortalSettings.Current
    3. Some objects can also be retrieved through Dependency Injection, using GetService<ISomeDnnType>()
    4. In general we recommend against using DNN specific objects this, because your work can then not be transported to another platform.
  3. Get DNN SQL Data
    1. Use standard DNN APIs
    2. You can also use Visual Query to retrieve data from DNN tables

Use 2sxc Objects and Services in Dnn Skins and Modules

👉🏽 See Guide to using 2sxc in Dnn Skins and Modules


History

  • 2sxc v1 was for Dnn 4 in 2012
  • 2sxc v14 requires Dnn 9.6.1 or newer and is fully integrated in the DNN Dependency injection, so DNN can get 2sxc services and vice versa.

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