Hi all,
in a custom module I get a warning saying
<code>Obsolete("Deprecated in 9.7.1. Scheduled for removal in v11.0.0, use DotNetNuke.Abstractions.IHostSettingsService instead.")</code>
The line that throws this warning is
<code>DotNetNuke.Entities.Controllers.HostController.Instance.GetSettingsDictionary().TryGetValue("FileExtensions", out allowedExtensions)</code>
Can anyone provide an example of how to replace this? (beside the fact that the warning is misleading, as it should be <code>DotNetNuke.Abstractions.<span style="background-color:Yellow;">Application.</span>IHostSettingsService</code>)
Happy DNNing! Michael
Thank you both,
Brian, if I understand that right, it is done like with the INavigationManager.
<code>public MyControl()<br /> {<br /> _hostSettings = DependencyProvider.GetRequiredService< IHostSettingsService >();<br /> }<br /> <br /> private readonly IHostSettingsService _hostSettings;<br /> <br /> protected void SomeMethod()<br /> {<br /> …<br /> string allowedExtensions;<br /> if (!(_hostSettings.GetSettingsDictionary().TryGetValue("FileExtensions", out allowedExtensions)))<br /> {<br /> … </code>
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 for the discussion of the open source CMS DNN platform and ecosystem.
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.