-
Notifications
You must be signed in to change notification settings - Fork 455
MultipleDatabase
shuxin edited this page Mar 24, 2023
·
5 revisions
1. 建立不同的上下文接口
public interface IDbContextA : IDbContext
{
}
public interface IDbContextB : IDbContext
{
}
public class DbContextA : MsSqlContext, IDbContextA
{
public DbContextA(string connString) : base(connString)
{
}
}
public class DbContextB : MsSqlContext, IDbContextB
{
public DbContextB(string connString) : base(connString)
{
}
}
2. 注入 IOC
public static class ServiceCollectionExtensions
{
public static IServiceCollection AddDatabase(this IServiceCollection services)
{
services.AddScoped<IDbContextA>(a =>
{
return new DbContextA("connection string A");
});
services.AddScoped<IDbContextB>(a =>
{
return new DbContextB("connection string B");
});
services.AddScoped<YourRepository>();
return services;
}
}
3. 使用
public class YourRepository
{
IDbContext _dbContextA;
IDbContext _dbContextB;
public YourRepository(IDbContextA dbContextA, IDbContextB dbContextB)
{
this._dbContextA = dbContextA;
this._dbContextB = dbContextB;
}
}
熬夜的时候容易引起脱发,熬夜时人的免疫力会下降,还会引起内分泌的变化,导致皮脂分泌增多,这些因素都不利于头发的生长,有可能引起脱发。如果出现熬夜脱发的情况,需要及时纠正日常的生活习惯,合理安排休息时间,早睡早起,适当的锻炼身体,多进食优质的蛋白质,增强身体的抵抗力,促进头发的生长。
发量有限,远离996!!!