OrchardCMS / OrchardCMS/OrchardCore.Samples
How to use the controllers and views in a multi-tenant application
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 417
- Forks
- 135
- PR merge metrics
- No merged PRs in 30d
Description
The sample multi-tenancy project (MultiTenantApplication.csproj) works fine with razor pages but how should we enable controllers and views?
Trying to add them by adding
builder.Services.AddControllersWithViews();
...
app.MapDefaultControllerRoute();
results in the error:
ArgumentException: Value cannot be null or empty. (Parameter 'areaName')
if instead of MapDefaultControllerRoute() I use endpoints like this:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute("MyDefaultRoute", "{controller=Home}/{action=Index}");
});
It works fine, but when I want to use DI to inject shell settings as in the razor pages sample in the index view
@inject ShellSettings settings
And use constructor injection
public class MessageController : Controller
{
private readonly ShellSettings _settings;
public MessageController(ShellSettings settings)
{
_settings = settings;
}
}
I get the error:
InvalidOperationException: Unable to resolve service for type 'OrchardCore.Environment.Shell.ShellSettings' while attempting to activate 'MultiTenantApplication.Controllers.MessageController'.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with MultiTenantApplication.csproj and trace the sample's Razor Pages setup alongside AddControllersWithViews and the routing calls shown in the issue. Inspect how ShellSettings is registered and consumed by the index view and MessageController; done means controllers and views work in the multi-tenant sample and ShellSettings can be injected without either reported exception.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100