SharedFlat and Multitenant UI

栏目: IT技术 · 发布时间: 4年前

内容简介:In myprevious post, I introducedOne way to make UI modifications is to have conditional logic in views. There is an extension method,This will look for an option registered using the

Introduction

In myprevious post, I introduced SharedFlat , a library for making multitenant ASP.NET Core apps easier to build. This time I’m going to talk about how can we customize the UI per tenant.

Using Conditional Logic in Views

One way to make UI modifications is to have conditional logic in views. There is an extension method, IsEnabledForTenant , that can be used to check if a specific property is set to true for the current tenant:

@if (this.IsEnabledForTenant("Foo"))
{
<p>Bar</p>
}

This will look for an option registered using the Options Pattern that was described in the previous post.

Another option is to check for a specific tenant, using the IsTenant extension method:

@if (this.IsTenant("abc"))
{
<p>abc</p>
}

For the exact same purpose we can also use the <tenant> tag helper :

<tenant name="xpto">
<p>xpto!</p>
</tenant>

If we wish to load a partial view, there’s another tag helper just for that, <tenant-partial> :

<tenant-partial tenant="xyz" name="xyzView"></tenant-partial>

This will conditionally load the xyzView file if the current tenant is xyz .

Using Different Files

A different approach would be to have different files (in different folders), one for each tenant. Say, for example, that you want to have a different folder per each tenant in your Views\<controller> folder. You just need to call AddTenantLocations when registering the services:

services
.AddTenantService()
.AddTenantLocations();

After this, if you have this folder structure:

  • Views

    • Home

      • abc

      • xyz

ASP.NET Core will load the views from the tenant-specific folder, ( abc or xyz ) and only if it cannot find the files there ASP.NET Core will it resort to the default ones (in Home or Shared ).

Finally, if you wish to load static files from a well-known location that refers to the tenant, you can do this:

<script src="~/@this.GetTenant()/index.js"></script>

Conclusion

This is as much as it goes for now for making the UI multitenant with SharedFlat. On the next post I will be talking about data, how to access databases in a multitenant way.


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

《电脑报》2005年合订本(上下)

《电脑报》2005年合订本(上下)

电脑报社主编 / 西南师范大学出版社 / 2006-1 / 45.00元

全套上、下两册,浓缩2005年电脑报精华文章;附录包含70余篇简明IT应用指南,涵盖软件、硬件、数码、网络四大领域,配赠权威实用的2005-2006中国计算机年鉴光盘,近1.4GB海量信息与资源超值奉献,提供2005-2006全系列硬件、数码产品资讯,兼具知识性与资料性,连结购买每年《电脑报合订本》,你将拥有一套完整的实用大型电脑文库。一起来看看 《《电脑报》2005年合订本(上下)》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试