Skip to content

Commit

Permalink
chore: update identity sample for v7 breaking changes (#825)
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewTriesToCode authored May 13, 2024
1 parent 276b3d7 commit 900cd52
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 11 additions & 8 deletions samples/net6.0/IdentitySample/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
using Finbuckle.MultiTenant.EntityFrameworkCore;
using Finbuckle.MultiTenant.Abstractions;
using Finbuckle.MultiTenant.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace IdentitySample.Data;

public class ApplicationDbContext : MultiTenantIdentityDbContext
{
private readonly AppTenantInfo _tenantInfo;
public ApplicationDbContext(IMultiTenantContextAccessor multiTenantContextAccessor, DbContextOptions options) : base(multiTenantContextAccessor, options)
{
}

public ApplicationDbContext(AppTenantInfo tenantInfo) : base(tenantInfo)
public ApplicationDbContext(IMultiTenantContextAccessor multiTenantContextAccessor) : base(multiTenantContextAccessor)
{
_tenantInfo = tenantInfo;
}

public ApplicationDbContext(AppTenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options)
public ApplicationDbContext(ITenantInfo tenantInfo) : base(tenantInfo)
{
_tenantInfo = tenantInfo;
// used for the design-time factory and progammatic migrations in program.cs
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(_tenantInfo.ConnectionString ?? throw new InvalidOperationException());
var tenantInfo = TenantInfo as AppTenantInfo;
optionsBuilder.UseSqlite(tenantInfo?.ConnectionString ?? throw new InvalidOperationException());
base.OnConfiguring(optionsBuilder);
}
}
4 changes: 1 addition & 3 deletions samples/net6.0/IdentitySample/Data/DesignTimeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ public class SharedDesignTimeFactory : IDesignTimeDbContextFactory<ApplicationDb
public ApplicationDbContext CreateDbContext(string[] args)
{
var tenantInfo = new AppTenantInfo{ ConnectionString = "Data Source=Data/SharedIdentity.db" };
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();

return new ApplicationDbContext(tenantInfo, optionsBuilder.Options);
return new ApplicationDbContext(tenantInfo);
}
}

0 comments on commit 900cd52

Please sign in to comment.