Create and Register Custom Services in Dnn
If you are creating your own solutions and want to provide the services to DNN or 2sxc code, this is what you need to know.
Note
This requires Dnn 9.4+
You need to create a class that implement IDnnStartup
like this
using azing.Catalog.Permissions;
using DotNetNuke.DependencyInjection;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
namespace azing.Catalog
{
public class StartupAzing : IDnnStartup
{
// This is the new v13 mode, requires DNN 9.44+
public void ConfigureServices(IServiceCollection services)
{
services.TryAddTransient<AppPermissions>();
}
}
}
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)
- Added ServiceKitLight for custom DataSources in 2sxc 15
- Added ServiceKit16 for 2sxc 16