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.
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
- In general, everything in 2sxc is the same for all platforms.
- For Dnn it's important to realize that its based on some older Frameworks
- .net Framework 4.7.2 as of DNN 9.6.1, or .net Framework 4.8 for the latest DNN
- Razor uses the fairly old MVC 3
- C# is also an older version, we believe ca. 6.0. For example, you cannot use
var x = x?.y?.zbecause it's not supported in this version.
- Dependency Injection is still fairly new in DNN
- not all DNN services are available in dependency injection
- not all DNN controls can use dependency injection
- 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
- General user, site (portal) and similar information
- Just use the
CmsContextobjects - eg.
- This is the same across platforms, so code written like this will also run on Oqtane
- Just use the
- Access really specific DNN objects
- Use the normal DNN API which is not dependency injection based.
- 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
- Some objects can also be retrieved through Dependency Injection, using
- In general we recommend against using DNN specific objects this, because your work can then not be transported to another platform.
- Get DNN SQL Data
- Use standard DNN APIs
- You can also use Visual Query to retrieve data from DNN tables
Use 2sxc Objects and Services in Dnn Skins and Modules
- 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
- 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)