[英]Does DBContext in startup.cs of .netcore Represent the entire database in the ASP application?
Is multiple DbContext
allowed or it is supposed to be only one in an entire ASP application? 是否允许使用多个
DbContext
或者在整个ASP应用程序中只能使用一个DbContext
?
Code Snippet from my Startup.cs
我的
Startup.cs
代码段
public IConfigurationRoot Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
services.AddDbContext<PatientContext> (options => options.UseSqlite("Data Source=MyDatabase.db"));
services.AddDbContext<AdminAccountContext> (options => options.UseSqlite("Data Source=MyDatabase.db"));
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
loggerFactory.AddConsole(Configuration.GetSection("Logging"));
loggerFactory.AddDebug();
if (env.IsDevelopment())
Clearly, it's allowed. 显然,这是允许的。 If they are pointing at two different databases, it's even necessary.
如果他们指向两个不同的数据库,则甚至有必要。 But even if not, it can be a useful way of differentiating the dependencies when they are consumed.
但是,即使不是,它也可能是区分依赖项时的一种有用方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.