当前位置: 首页>>代码示例>>C#>>正文


C# DbContextOptionsBuilder.UseInternalServiceProvider方法代码示例

本文整理汇总了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);
                     }
                 });
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:12,代码来源:OrdersContext.cs

示例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);
     }
 }
开发者ID:yonglehou,项目名称:dotNETCore-Extensions,代码行数:12,代码来源:DbContextModelBindingFilter.cs

示例3: OnConfiguring

 protected internal override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
     => optionsBuilder
         .UseInternalServiceProvider(_serviceProvider)
         .UseInMemoryDatabase();
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:4,代码来源:ChangeTrackerTest.cs

示例4: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
     => optionsBuilder
         .UseInternalServiceProvider(_serviceProvider)
         .UseSqlServer(SqlServerTestStore.CreateConnectionString(_databaseName));
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:4,代码来源:SequenceEndToEndTest.cs

示例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();
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:21,代码来源:ConfigPatternsInMemoryTest.cs

示例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();
        }
开发者ID:RickyLin,项目名称:EntityFramework,代码行数:14,代码来源:ConfigPatternsInMemoryTest.cs

示例7: OnConfiguring

 protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) => optionsBuilder
     .UseInternalServiceProvider(_serviceProvider)
     .UseSqlServer(SqlServerNorthwindContext.ConnectionString);
开发者ID:ChuYuzhi,项目名称:EntityFramework,代码行数:3,代码来源:SqlServerConfigPatternsTest.cs


注:本文中的DbContextOptionsBuilder.UseInternalServiceProvider方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。