Bug Affects...
[x] Razor templating
[x] Platform parts (Dnn/Oqtane)
Current Behavior / Expected Behavior
Since 2sxc v13+ we've been able to call GetService<>() to use DI to get available DNN service interfaces like INavigationManager and others.
I recently needed to use DataTables.net, so when I wanted to get the two assets added to my page I decided to use the new fluent method to add client resources, CDF. This was added in DNN v10.02.00, so I am trying to get the services, IClientResourceController.
The following code WORKS, "the DNN way" in a 2sxc View or a RazorHost script.
@using System.Web @* HttpContext *@
@using Microsoft.Extensions.DependencyInjection @* IServiceScope *@
@using DotNetNuke.Common.Extensions @* extends HttpContext for GetScope() *@
@using DotNetNuke.Abstractions.ClientResources @* IClientResourceController *@
@using DotNetNuke.Web.Client.ResourceManager @* FileOrder, ClientResourceProviders *@
@{
@* DNN 10.02+ CDF way to get Client Resources (CSS, JS, etc) on the page - IClientResourceController *@
IServiceScope currentScope = HttpContext.Current.GetScope();
IServiceProvider serviceProvider = currentScope.ServiceProvider;
var clientResourceController = serviceProvider.GetRequiredService<IClientResourceController>();
clientResourceController
.CreateScript("//cdn.datatables.net/2.3.7/js/dataTables.min.js")
.SetProvider(ClientResourceProviders.DnnPageHeaderProvider)
.SetPriority(FileOrder.Js.DefaultPriority)
.Register()
;
}
The following code DOES NOT work, "the 2sxc way"** in a 2sxc View.
@inherits Custom.Hybrid.RazorTyped
@* this is the 2sxc version, only works in 2sxc *@
@using DotNetNuke.Abstractions.ClientResources @* IClientResourceController *@
@using DotNetNuke.Web.Client.ResourceManager @* FileOrder, ClientResourceProviders *@
@{
@* DNN 10.02+ CDF way to get Client Resources (CSS, JS, etc) on the page - IClientResourceController *@
var clientResourceController = GetService<IClientResourceController>();
clientResourceController
.CreateScript("//cdn.datatables.net/2.3.7/js/dataTables.min.js")
.SetProvider(ClientResourceProviders.DnnPageHeaderProvider)
.SetPriority(FileOrder.Js.DefaultPriority)
.Register()
;
If I output clientResourceController.GetType().ToString() in both versions, they appear to be the same, "DotNetNuke.Web.Client.ResourceManager.ClientResourceController".
There are no errors in the 2sxc version, but the resource does not get added/registered.
To Reproduce (Steps, Videos, Screenshots, Apps)
You should be able to copy the 2 examples above into any 2sxc View and then check your page source looking for the script.
Your environment
- 2sxc version(s): 21.05.00
- Browser: all/any
- DNN / Oqtane: Dnn 10.02.03
- Hosting platform: IIS 10+, Windows Server 2022
- Ui Languages: any/all | English
Additional context
Page source with the DNN .GetRequiredService version:
Page source with the 2sxc GetService version, script not there:

Bug Affects...
[x] Razor templating
[x] Platform parts (Dnn/Oqtane)
Current Behavior / Expected Behavior
Since 2sxc v13+ we've been able to call
GetService<>()to use DI to get available DNN service interfaces like INavigationManager and others.I recently needed to use DataTables.net, so when I wanted to get the two assets added to my page I decided to use the new fluent method to add client resources, CDF. This was added in DNN v10.02.00, so I am trying to get the services, IClientResourceController.
The following code WORKS, "the DNN way" in a 2sxc View or a RazorHost script.
The following code DOES NOT work, "the 2sxc way"** in a 2sxc View.
If I output
clientResourceController.GetType().ToString()in both versions, they appear to be the same, "DotNetNuke.Web.Client.ResourceManager.ClientResourceController".There are no errors in the 2sxc version, but the resource does not get added/registered.
To Reproduce (Steps, Videos, Screenshots, Apps)
You should be able to copy the 2 examples above into any 2sxc View and then check your page source looking for the script.
Your environment
Additional context
Page source with the DNN
.GetRequiredServiceversion:Page source with the 2sxc
GetServiceversion, script not there: