Skip to content

Commit

Permalink
add some using and task
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali-YousefiTelori committed Sep 10, 2023
1 parent 43b48ec commit 55478bb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task Main(string[] args)
app.Services.AddTransient(serviceProvider => new MyTestContext(serviceProvider.GetService<IEntityFrameworkCoreDatabaseBuilder>()));
app.Services.AddScoped<IEntityFrameworkCoreDatabaseBuilder>(serviceProvider => new DatabaseBuilder());

var build = app.Build<MyTestContext>();
var build = await app.Build<MyTestContext>();
build.MapControllers();
build.Run();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public static async Task Build<TContext>(this IApplicationBuilder app)
var dbbuilder = new DatabaseCreator();
using var context = scope.ServiceProvider.GetRequiredService<TContext>();
dbbuilder.Initialize(context);
var uow = scope.ServiceProvider.GetRequiredService<IUnitOfWork>() as UnitOfWork;
using var uow = scope.ServiceProvider.GetRequiredService<IUnitOfWork>() as UnitOfWork;
await uow.Initialize("TextExample", "http://localhost:6041", typeof(TContext)).ConfigureAwait(false);
}
var build = app.Build();
Expand All @@ -121,7 +121,7 @@ public static async Task Build<TContext>(this IApplicationBuilder app)
/// <typeparam name="TContext"></typeparam>
/// <param name="app"></param>
/// <returns></returns>
public static WebApplication Build<TContext>(this WebApplicationBuilder app)
public static async Task<WebApplication> Build<TContext>(this WebApplicationBuilder app)
where TContext : RelationalCoreContext
{
var build = app.Build();
Expand All @@ -139,6 +139,8 @@ public static WebApplication Build<TContext>(this WebApplicationBuilder app)
var dbbuilder = new DatabaseCreator();
using var context = scope.ServiceProvider.GetRequiredService<TContext>();
dbbuilder.Initialize(context);
using var uow = scope.ServiceProvider.GetRequiredService<IUnitOfWork>() as UnitOfWork;
await uow.Initialize("TextExample", "http://localhost:6041", typeof(TContext)).ConfigureAwait(false);
}
return build;
}
Expand Down

0 comments on commit 55478bb

Please sign in to comment.