Skip to content

ShardingRuntimeBuilder方式导致内存溢出 #304

@TanShuJun1985

Description

@TanShuJun1985

我无法在 Startup.cs中使用,因为我的ApplicationDbContext必须在服务器启动完成后再注册的:
services.AddDbContext《ApplicationDbContext>((sp, b) =>
{
var tenantManager = sp.GetRequiredService《ITenantManager>();
if (shardingRuntimeContext!= null)
{
b.UseDefaultSharding《ApplicationDbContext>(shardingRuntimeContext);
}
});
以上代码我无法在 Startup.cs中使用,也就是在服务器启动期间。

所以我在使用ShardingRuntimeBuilder方式,并在ApplicationDbContext的OnConfiguring方法里来实现optionsBuilder.UseDefaultSharding(),但是会出现OnConfiguring方法被无限循环调用,导致内存溢出:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        if (shardingRuntimeContext != null)
        {
            optionsBuilder.UseDefaultSharding《ApplicationDbContext>(shardingRuntimeContext);
        }
        
        base.OnConfiguring(optionsBuilder);
    }

shardingRuntimeContext变量获取相关的代码这里已经删除省略

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions