public static IObjectFieldDescriptor UseDbContext <TDbContext>(this IObjectFieldDescriptor descriptor)
     where TDbContext : DbContext
 {
     return(descriptor.UseScopedService(
                create: s => s.GetRequiredService <IDbContextFactory <TDbContext> >().CreateDbContext(),
                dispose: (s, c) => c.DisposeAsync()));
 }
 public static IObjectFieldDescriptor UseAsyncSessionWithDatabase(
     this IObjectFieldDescriptor descriptor,
     string dbName)
 {
     return(descriptor.UseScopedService(
                s => s.GetRequiredService <IDriver>().AsyncSession(o => o.WithDatabase(dbName))));
 }
 public static IObjectFieldDescriptor UseDbContext <TDbContext>(
     this IObjectFieldDescriptor descriptor)
     where TDbContext : DbContext
 {
     return(descriptor.UseScopedService <TDbContext>(
                create: s => s.GetRequiredService <DbContextPool <TDbContext> >().Rent(),
                dispose: (s, c) => s.GetRequiredService <DbContextPool <TDbContext> >().Return(c)));
 }
示例#4
0
 public static IObjectFieldDescriptor UseDbContext <T>(this IObjectFieldDescriptor descriptor)
     where T : DbContext
 {
     return(descriptor.UseScopedService(
                serviceProvider => serviceProvider.GetRequiredService <IDbContextFactory <T> >().CreateDbContext(),
                disposeAsync: (_, context) => context.DisposeAsync()
                ));
 }