Skip to content

Commit

Permalink
Updated CustomWebApplicationDbContextFactory to remove current dbcont…
Browse files Browse the repository at this point in the history
…ext before adding test ones.
  • Loading branch information
Farshad DASHTI authored and Farshad DASHTI committed Oct 11, 2024
1 parent 7f4a841 commit 5b6ffda
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ protected override void ConfigureWebHost(IWebHostBuilder builder)
var dbContextType = entry.Key;
var seedAction = entry.Value;

var dbContextDescriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbContextOptions<>).MakeGenericType(dbContextType));
if (dbContextDescriptor != null)
{
services.Remove(dbContextDescriptor);
}

var dbConnectionDescriptor = services.SingleOrDefault(
d => d.ServiceType == typeof(DbConnection));
if (dbConnectionDescriptor != null)
{
services.Remove(dbConnectionDescriptor);
}


var createDbContextMethod = typeof(DbContextHelper).GetMethod(nameof(DbContextHelper.CreateDbContext))
?.MakeGenericMethod(dbContextType);

Expand Down

0 comments on commit 5b6ffda

Please sign in to comment.