OrchardCore Multi Tennant с веб-API - PullRequest
       60

OrchardCore Multi Tennant с веб-API

0 голосов
/ 18 июня 2020

Можно ли использовать мультитеннантные функции OrchardCore в проекте веб-API?

Я создал пустой проект в Visual Studio, используя "ASP. NET Core веб-приложение "->" API "и добавил ссылку на OrchardCore.Application.Mvc.Targets.

Мой класс StartUp выглядит так:

public class Startup
  {
    public Startup(IConfiguration configuration)
    {
      Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    public void ConfigureServices(IServiceCollection services)
    {
      services.AddControllers();
      services.AddOrchardCore().AddMvc().WithTenants();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
      if (env.IsDevelopment())
      {
        app.UseDeveloperExceptionPage();
      }

      app.UseOrchardCore(builder =>
      {
        builder.UseHttpsRedirection();
        builder.UseRouting();
        builder.UseAuthorization();
        builder.UseEndpoints(endpoints => { endpoints.MapControllers(); });
      });
    }
}

Я также добавил следующее в appsetting.json:

"OrchardCore": {
"Default": {
  "State": "Running",
  "RequestUrlHost": null,
  "RequestUrlPrefix": null,
  "Features": [],
  "CustomTitle": "Default Tenant",
  "CustomSetting": "Custom setting for Default tenant"
},
"CustomerA": {
  "State": "Running",
  "RequestUrlHost": null,
  "RequestUrlPrefix": "customer-a",
  "Features": [ "Module1" ],
  "CustomTitle": "Customer A",
  "CustomSetting": "Custom setting for Customer A"
},
"CustomerB": {
  "State": "Running",
  "RequestUrlHost": null,
  "RequestUrlPrefix": "customer-b",
  "Features": [ "Module1", "Module2" ],
  "CustomTitle": "Customer B",
  "CustomSetting": "Custom setting for Customer B"
}

Когда я запускаю приложение, маршрут по умолчанию https://localhost:44370/weatherforecast работает, но https://localhost:44370/customer-b/weatherforecast возвращает 404.

Я думаю, что это может быть способ, которым я использую AddControllers или UseOrchardCore. Например, если я закомментирую AddControllers, я получаю InvalidOperationException, потому что UseAuthorization больше не работает.

...