Skip to content

Commit

Permalink
Use GetSettingsAsync().
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahelsaig committed Sep 24, 2024
1 parent 196cce6 commit 86cab7d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
6 changes: 3 additions & 3 deletions Lombiq.TrainingDemo/Controllers/SiteSettingsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ public async Task<string> SiteName() =>
// give it a value on the Dashboard if you want to see something here.
public async Task<string> DemoSettings()
{
// As mentioned the custom settings objects are serialized into the ISite object so use the .As<>() helper to
// access it as you see below.
var messageFromSiteSettings = (await _siteService.GetSiteSettingsAsync()).As<DemoSettings>().Message;
// As mentioned the custom settings objects are serialized into the ISite object. We could use the .As<>()
// helper to access it, but Orchard Core also has the built-in GetSettingsAsync<>() shortcut to do just that.
var messageFromSiteSettings = (await _siteService.GetSettingsAsync<DemoSettings>()).Message;

// But as you've seen in DemoSettings.cs our site settings are also Options so we can use it as such too:
var messageFromOptions = _demoSettings.Message;
Expand Down
4 changes: 1 addition & 3 deletions Lombiq.TrainingDemo/Services/DemoSettingsConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,7 @@ public void Configure(DemoSettings options)
// out what we have there related to settings and come back!

// Unfortunately, no async here so we need to run this synchronously.
var settings = _siteService.GetSiteSettingsAsync()
.GetAwaiter().GetResult()
.As<DemoSettings>();
var settings = _siteService.GetSettingsAsync<DemoSettings>().GetAwaiter().GetResult();

options.Message = settings.Message;
}
Expand Down

0 comments on commit 86cab7d

Please sign in to comment.