-
Notifications
You must be signed in to change notification settings - Fork 455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
MultiTenancy多租户,不同DB的方式,netcore里如何注入连接字符串 #261
Comments
在创建dbconext的地方呗?? |
尝试了 但是好像还是有问题 大佬能不能放个netcore的demo呀 |
services.AddSingleton<IHttpContextAccessor, HttpContextAccessor>();
services.AddScoped<Chloe.IDbContext>(a =>
{
var httpRequest = a.GetService<IHttpContextAccessor>().HttpContext.Request;
string connectionString = "根据 httpRequest 拼接";
return new Chloe.SqlServer.MsSqlContext(connectionString);
}); |
这个跟你提供的逻辑是一样的呀 测试没通过耶 |
没通过原因是啥? |
解决了 谢谢大佬 |
shuxinqin
changed the title
多租户,不同DB的方式,netcore里如何注入连接字符串
MultiTenancy多租户,不同DB的方式,netcore里如何注入连接字符串
Jul 31, 2021
其实大佬可以考虑加个多数据库上下文注入的功能,能够动态切换就可以,可以满足多租户的要求了,然后再解决跨库事务 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
如题,
要实现不同租户的数据库切换,通过requeHeader里通过参数获取到要切换的db参数,从而组合连接字符串,
现在的问题是 字符串组合好了,现在不知道如何动态的切换connStr。
请赐教!祝愉快!
The text was updated successfully, but these errors were encountered: