Skip to content

Instantly share code, notes, and snippets.

@sfmskywalker
Created June 27, 2018 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sfmskywalker/19f849a618a33e0c266b5dff2b313c9c to your computer and use it in GitHub Desktop.
Save sfmskywalker/19f849a618a33e0c266b5dff2b313c9c to your computer and use it in GitHub Desktop.
Partial Startup
app.UseOrchardCore(a => a.Run(async context =>
{
// ShellSettings provide the tenant's configuration.
var shellSettings = context.RequestServices.GetRequiredService<ShellSettings>();
// Read the tenant-specific custom setting.
var customSetting = shellSettings.Configuration["CustomSetting"];
// Resolve all registered IMessageProvider services.
var messageProviders = context.RequestServices.GetServices<IMessageProvider>();
// Invoke all IMessageProviders.
var messages = (await Task.WhenAll(messageProviders.Select(async x => await x.GetMessageAsync()))).ToList();
// Add the custom setting as a message. Alternatively, could have implemented another IMessageProvider that reads the
messages.Insert(0, customSetting);
// Concatenate all messages.
var output = string.Join("\r\n", messages);
// Write the output string to the response stream.
await context.Response.WriteAsync(output);
}));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment