Hi all,
in a custom module I get a warning saying
Obsolete("Deprecated in 9.7.1. Scheduled for removal in v11.0.0, use DotNetNuke.Abstractions.IHostSettingsService instead.")
The line that throws this warning is
DotNetNuke.Entities.Controllers.HostController.Instance.GetSettingsDictionary().TryGetValue("FileExtensions", out allowedExtensions)
Can anyone provide an example of how to replace this? (beside the fact that the warning is misleading, as it should be DotNetNuke.Abstractions.Application.IHostSettingsService)
DotNetNuke.Abstractions.Application.IHostSettingsService
Happy DNNing! Michael
Michael TobischDNN★MVP
DotNetNuke.Entities.Host.Host.AllowedExtensionWhitelist
Thank you both,
Brian, if I understand that right, it is done like with the INavigationManager.
public MyControl() { _hostSettings = DependencyProvider.GetRequiredService< IHostSettingsService >(); } private readonly IHostSettingsService _hostSettings; protected void SomeMethod() { … string allowedExtensions; if (!(_hostSettings.GetSettingsDictionary().TryGetValue("FileExtensions", out allowedExtensions))) { …
That did work (without the spaces inside the angle brackets), thank you...
Hi,
When I try something like this:
Snippet <!--StartFragment-->
IHostSettingsService hostSettingsService = DotNetNuke.Common.Globals.DependencyProvider.GetRequiredService < IHostSettingsService > ();
<!--EndFragment-->
It doesn't work. Error: "'Globals' does not contain a definition for 'DependencyProvider'"
This error makes sense (cannot access it from my code) because DependencyProvider is internal in Dotnetnuke.dll.
internal static IServiceProvider DependencyProvider { get { return Globals.dependencyProvider; } set { Globals.dependencyProvider = value; INotifyPropertyChanged notifyPropertyChanged = Globals.dependencyProvider as INotifyPropertyChanged; INotifyPropertyChanged notifyPropertyChanged1 = notifyPropertyChanged; if (notifyPropertyChanged == null) { Globals.OnDependencyProviderChanged(null, null); return; } notifyPropertyChanged1.PropertyChanged += new PropertyChangedEventHandler(Globals.OnDependencyProviderChanged); } }
Therefore, I don't understand how can I get and save host settings without using deprecated code.
Any ideas?
EDIT:
It does work for example in this DNN's code: \Dnn.Platform\Dnn.AdminExperience\Dnn.PersonaBar.Extensions\Components\TaskScheduler\TaskSchedulerController.cs, because \Dnn.Platform\DNN Platform\Library\Properties\AssemblyInfo.cs says "[assembly: InternalsVisibleTo("Dnn.PersonaBar.Library")] "
I coudn't find any way to get & save host settings from non-dnn core code.
Thanks
I was easier than I thought, and without using IHostSettingsService.
At least for now, I don't get any obsolete warning when using code like this:
var ctl = new HostController(); var myValue = ctl.GetString("myKey"); ctl.Update(key: "mykey", value: myValue, clearCache: true);
Thanks,
H
These Forums are dedicated to the discussion of DNN Platform.
For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:
Awesome! Simply post in the forums using the link below and we'll get you started.