Skip to content

How to use the controllers and views in a multi-tenant application #33

Description

@VahidNaderi

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'.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions