实例介绍
MultiTenancyServer是一个旨在轻松为任何代码库添加多租户支持的轻量级包。它的设计受到ASP.NET Core Identity的强烈影响。您可以在不向任何类或实体添加任何租户键属性的情况下,为您的模型添加多租户支持。使用ASP.NET Core,可以通过自定义域名、子域、部分主机名、HTTP请求头、子路径或部分URL路径、查询字符串参数、认证用户声明或自定义请求解析器实现来检索当前租户。使用Entity Framework Core,租户键作为影子属性(或可选的具体属性)添加,并通过全局查询过滤器强制执行,所有可配置选项都可以从默认值设置或覆盖每个实体。
public class Tenant : TenancyTenant
{
public string Name { get; set; }
}
public void ConfigureServices(IServiceCollection services)
{
// 示例代码省略
}
public void Configure(IApplicationBuilder app)
{
// 示例代码省略
}
本文档详细介绍了如何定义模型、注册服务、添加中间件和配置实体,以及如何结合ASP.NET Core Identity和IdentityServer4一起使用MultiTenancyServer。【实例截图】
【核心代码】
文件清单
└── MultiTenancyServer-e09abba42961ca0774ee5ad9f40705c53bc15299
├── Directory.Build.props
├── icon.png
├── LICENSE
├── MultiTenancyServer.sln
├── README.md
├── samples
│ ├── AspNetIdentityAndEFCore
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── Areas
│ │ │ └── Identity
│ │ │ └── Pages
│ │ │ └── _ViewStart.cshtml
│ │ ├── AspNetIdentityAndEFCore.csproj
│ │ ├── Controllers
│ │ │ └── HomeController.cs
│ │ ├── Data
│ │ │ ├── ApplicationDbContext.cs
│ │ │ └── Migrations
│ │ │ ├── 20191029065610_AspIdentityWithMultiTenancy.cs
│ │ │ ├── 20191029065610_AspIdentityWithMultiTenancy.Designer.cs
│ │ │ └── ApplicationDbContextModelSnapshot.cs
│ │ ├── Models
│ │ │ ├── ApplicationTenant.cs
│ │ │ ├── ApplicationUser.cs
│ │ │ └── ErrorViewModel.cs
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ └── launchSettings.json
│ │ ├── SeedData.cs
│ │ ├── Startup.cs
│ │ ├── Views
│ │ │ ├── Home
│ │ │ │ ├── Index.cshtml
│ │ │ │ └── Privacy.cshtml
│ │ │ ├── Shared
│ │ │ │ ├── Error.cshtml
│ │ │ │ ├── _Layout.cshtml
│ │ │ │ ├── _LoginPartial.cshtml
│ │ │ │ └── _ValidationScriptsPartial.cshtml
│ │ │ ├── _ViewImports.cshtml
│ │ │ └── _ViewStart.cshtml
│ │ └── wwwroot
│ │ ├── css
│ │ │ └── site.css
│ │ ├── favicon.ico
│ │ ├── js
│ │ │ └── site.js
│ │ └── lib
│ │ ├── bootstrap
│ │ │ ├── dist
│ │ │ │ ├── css
│ │ │ │ │ ├── bootstrap.css
│ │ │ │ │ ├── bootstrap.css.map
│ │ │ │ │ ├── bootstrap-grid.css
│ │ │ │ │ ├── bootstrap-grid.css.map
│ │ │ │ │ ├── bootstrap-grid.min.css
│ │ │ │ │ ├── bootstrap-grid.min.css.map
│ │ │ │ │ ├── bootstrap.min.css
│ │ │ │ │ ├── bootstrap.min.css.map
│ │ │ │ │ ├── bootstrap-reboot.css
│ │ │ │ │ ├── bootstrap-reboot.css.map
│ │ │ │ │ ├── bootstrap-reboot.min.css
│ │ │ │ │ └── bootstrap-reboot.min.css.map
│ │ │ │ └── js
│ │ │ │ ├── bootstrap.bundle.js
│ │ │ │ ├── bootstrap.bundle.js.map
│ │ │ │ ├── bootstrap.bundle.min.js
│ │ │ │ ├── bootstrap.bundle.min.js.map
│ │ │ │ ├── bootstrap.js
│ │ │ │ ├── bootstrap.js.map
│ │ │ │ ├── bootstrap.min.js
│ │ │ │ └── bootstrap.min.js.map
│ │ │ └── LICENSE
│ │ ├── jquery
│ │ │ ├── dist
│ │ │ │ ├── jquery.js
│ │ │ │ ├── jquery.min.js
│ │ │ │ └── jquery.min.map
│ │ │ └── LICENSE.txt
│ │ ├── jquery-validation
│ │ │ ├── dist
│ │ │ │ ├── additional-methods.js
│ │ │ │ ├── additional-methods.min.js
│ │ │ │ ├── jquery.validate.js
│ │ │ │ └── jquery.validate.min.js
│ │ │ └── LICENSE.md
│ │ └── jquery-validation-unobtrusive
│ │ ├── jquery.validate.unobtrusive.js
│ │ ├── jquery.validate.unobtrusive.min.js
│ │ └── LICENSE.txt
│ ├── Int64AspNetIdentityAndEFCore
│ │ ├── appsettings.Development.json
│ │ ├── appsettings.json
│ │ ├── Areas
│ │ │ └── Identity
│ │ │ └── Pages
│ │ │ └── _ViewStart.cshtml
│ │ ├── Controllers
│ │ │ └── HomeController.cs
│ │ ├── Data
│ │ │ ├── ApplicationDbContext.cs
│ │ │ └── Migrations
│ │ │ ├── 20191029065621_AspIdentityWithMultiTenancy.cs
│ │ │ ├── 20191029065621_AspIdentityWithMultiTenancy.Designer.cs
│ │ │ └── ApplicationDbContextModelSnapshot.cs
│ │ ├── Int64AspNetIdentityAndEFCore.csproj
│ │ ├── Models
│ │ │ ├── ApplicationTenant.cs
│ │ │ ├── ApplicationUser.cs
│ │ │ └── ErrorViewModel.cs
│ │ ├── Program.cs
│ │ ├── Properties
│ │ │ └── launchSettings.json
│ │ ├── SeedData.cs
│ │ ├── Startup.cs
│ │ ├── Views
│ │ │ ├── Home
│ │ │ │ ├── Index.cshtml
│ │ │ │ └── Privacy.cshtml
│ │ │ ├── Shared
│ │ │ │ ├── Error.cshtml
│ │ │ │ ├── _Layout.cshtml
│ │ │ │ ├── _LoginPartial.cshtml
│ │ │ │ └── _ValidationScriptsPartial.cshtml
│ │ │ ├── _ViewImports.cshtml
│ │ │ └── _ViewStart.cshtml
│ │ └── wwwroot
│ │ ├── css
│ │ │ └── site.css
│ │ ├── favicon.ico
│ │ ├── js
│ │ │ └── site.js
│ │ └── lib
│ │ ├── bootstrap
│ │ │ ├── dist
│ │ │ │ ├── css
│ │ │ │ │ ├── bootstrap.css
│ │ │ │ │ ├── bootstrap.css.map
│ │ │ │ │ ├── bootstrap-grid.css
│ │ │ │ │ ├── bootstrap-grid.css.map
│ │ │ │ │ ├── bootstrap-grid.min.css
│ │ │ │ │ ├── bootstrap-grid.min.css.map
│ │ │ │ │ ├── bootstrap.min.css
│ │ │ │ │ ├── bootstrap.min.css.map
│ │ │ │ │ ├── bootstrap-reboot.css
│ │ │ │ │ ├── bootstrap-reboot.css.map
│ │ │ │ │ ├── bootstrap-reboot.min.css
│ │ │ │ │ └── bootstrap-reboot.min.css.map
│ │ │ │ └── js
│ │ │ │ ├── bootstrap.bundle.js
│ │ │ │ ├── bootstrap.bundle.js.map
│ │ │ │ ├── bootstrap.bundle.min.js
│ │ │ │ ├── bootstrap.bundle.min.js.map
│ │ │ │ ├── bootstrap.js
│ │ │ │ ├── bootstrap.js.map
│ │ │ │ ├── bootstrap.min.js
│ │ │ │ └── bootstrap.min.js.map
│ │ │ └── LICENSE
│ │ ├── jquery
│ │ │ ├── dist
│ │ │ │ ├── jquery.js
│ │ │ │ ├── jquery.min.js
│ │ │ │ └── jquery.min.map
│ │ │ └── LICENSE.txt
│ │ ├── jquery-validation
│ │ │ ├── dist
│ │ │ │ ├── additional-methods.js
│ │ │ │ ├── additional-methods.min.js
│ │ │ │ ├── jquery.validate.js
│ │ │ │ └── jquery.validate.min.js
│ │ │ └── LICENSE.md
│ │ └── jquery-validation-unobtrusive
│ │ ├── jquery.validate.unobtrusive.js
│ │ ├── jquery.validate.unobtrusive.min.js
│ │ └── LICENSE.txt
│ └── README.md
└── src
├── AspNetCore
│ ├── AspNetCore.csproj
│ ├── Extensions
│ │ ├── ApplicationBuilderExtensions.cs
│ │ ├── ServiceCollectionExtensions.cs
│ │ └── TenancyBuilderExtensions.cs
│ ├── Hosting
│ │ └── TenancyMiddleware.cs
│ ├── HttpTenancyProvider.cs
│ └── Parsers
│ ├── CustomParser.cs
│ ├── DomainParser.cs
│ ├── HeaderParser.cs
│ ├── HostParser.cs
│ ├── IRequestParser.cs
│ ├── PathParser.cs
│ ├── QueryParser.cs
│ ├── RegexRequestParser.cs
│ ├── RequestParser.cs
│ └── UserClaimParser.cs
├── Core
│ ├── Configuration
│ │ └── TenancyBuilder.cs
│ ├── Core.csproj
│ ├── CrossTenancyAccessViolationException.cs
│ ├── Extensions
│ │ └── ServiceCollectionExtensions.cs
│ ├── ITenancyContext.cs
│ ├── ITenancyProvider.cs
│ ├── Models
│ │ └── ITenanted.cs
│ ├── Options
│ │ ├── NullTenantReferenceHandling.cs
│ │ ├── TenancyOptions.cs
│ │ ├── TenantOptions.cs
│ │ └── TenantReferenceOptions.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Services
│ │ ├── ITenantValidator.cs
│ │ └── TenantValidator.cs
│ ├── Stores
│ │ ├── IQueryableTenantStore.cs
│ │ └── ITenantStore.cs
│ ├── TenancyAccessHelper.cs
│ ├── TenancyContext.cs
│ ├── TenancyError.cs
│ ├── TenancyErrorDescriber.cs
│ ├── TenancyResult.cs
│ └── TenantManager.cs
├── EFCore
│ ├── EFCore.csproj
│ ├── Extensions
│ │ ├── TenancyBuilderExtensions.cs
│ │ ├── TenancyEFExtensions.cs
│ │ └── TenantContextModelBuilderExtensions.cs
│ ├── ITenantDbContext.cs
│ ├── TableConfiguration.cs
│ ├── TenancyModelState.cs
│ ├── TenantDbContext.cs
│ ├── TenantStore.cs
│ └── TenantStoreOptions.cs
└── Stores
├── InMemoryTenantStore.cs
├── Stores.csproj
├── TenancyBuilderExtensions.cs
├── TenancyTenant.cs
└── TenantStoreBase.cs
67 directories, 180 files
标签:
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论