本文整理汇总了C#中DbContextOptionsBuilder.UseInternalServiceProvider方法的典型用法代码示例。如果您正苦于以下问题:C# DbContextOptionsBuilder.UseInternalServiceProvider方法的具体用法?C# DbContextOptionsBuilder.UseInternalServiceProvider怎么用?C# DbContextOptionsBuilder.UseInternalServiceProvider使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DbContextOptionsBuilder
的用法示例。
在下文中一共展示了DbContextOptionsBuilder.UseInternalServiceProvider方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseInternalServiceProvider(_serviceProvider)
.UseSqlServer(
_connectionString,
b =>
{
if (_disableBatching)
{
b.MaxBatchSize(1);
}
});
示例2: OnActionExecuting
public void OnActionExecuting(ActionExecutingContext context)
{
var pending = context.ActionArguments.Where(x => x.Value is DbContext).Select(x => x.Value as DbContext);
foreach(var x in pending)
{
var type = typeof(DbContext);
var field = type.GetRuntimeFields().Single(y => y.Name == "_options");
var opt = new DbContextOptionsBuilder((DbContextOptions)field.GetValue(x));
opt.UseInternalServiceProvider(context.HttpContext.RequestServices);
field.SetValue(x, opt.Options);
}
}
示例3: OnConfiguring
protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseInternalServiceProvider(_serviceProvider)
.UseInMemoryDatabase();
示例4: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseInternalServiceProvider(_serviceProvider)
.UseSqlServer(SqlServerTestStore.CreateConnectionString(_databaseName));
示例5: Can_inject_different_configurations_into_different_contexts
public void Can_inject_different_configurations_into_different_contexts()
{
var blogOptions = new DbContextOptionsBuilder<InjectDifferentConfigurationsBlogContext>()
.UseInMemoryDatabase();
var accountOptions = new DbContextOptionsBuilder<InjectDifferentConfigurationsAccountContext>()
.UseInMemoryDatabase();
var serviceProvider = new ServiceCollection()
.AddTransient<InjectDifferentConfigurationsBlogContext>()
.AddTransient<InjectDifferentConfigurationsAccountContext>()
.AddTransient<InjectDifferentConfigurationsBlogController>()
.AddTransient<InjectDifferentConfigurationsAccountController>()
.AddSingleton(p => blogOptions.UseInternalServiceProvider(p).Options)
.AddSingleton(p => accountOptions.UseInternalServiceProvider(p).Options)
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
serviceProvider.GetRequiredService<InjectDifferentConfigurationsBlogController>().Test();
serviceProvider.GetRequiredService<InjectDifferentConfigurationsAccountController>().Test();
}
示例6: Can_register_context_and_configuration_with_DI_container_and_have_both_injected
public void Can_register_context_and_configuration_with_DI_container_and_have_both_injected()
{
var optionsBuilder = new DbContextOptionsBuilder()
.UseInMemoryDatabase();
var serviceProvider = new ServiceCollection()
.AddTransient<InjectContextAndConfigurationBlogContext>()
.AddTransient<InjectContextAndConfigurationController>()
.AddSingleton(p => optionsBuilder.UseInternalServiceProvider(p).Options)
.AddEntityFrameworkInMemoryDatabase()
.BuildServiceProvider();
serviceProvider.GetRequiredService<InjectContextAndConfigurationController>().Test();
}
示例7: OnConfiguring
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder
.UseInternalServiceProvider(_serviceProvider)
.UseSqlServer(SqlServerNorthwindContext.ConnectionString);