Skip to content

Commit

Permalink
chore: update sample projects
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewTriesToCode committed Apr 21, 2024
1 parent b354838 commit 664628f
Show file tree
Hide file tree
Showing 12 changed files with 52 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,12 @@
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<!-- <ItemGroup>-->
<!-- <PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="7.*" />-->
<!-- </ItemGroup>-->

<ItemGroup>
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="6.*" />
<ProjectReference Include="..\..\..\src\Finbuckle.MultiTenant.AspNetCore\Finbuckle.MultiTenant.AspNetCore.csproj" />
</ItemGroup>

</Project>
4 changes: 0 additions & 4 deletions samples/net6.0/BasePathStrategySample/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ else
<td>@nameof(Model.TenantInfo.Name)</td>
<td>@Model.TenantInfo.Name</td>
</tr>
<tr>
<td>@nameof(Model.TenantInfo.ConnectionString)</td>
<td>@Model.TenantInfo.ConnectionString</td>
</tr>
</tbody>

</table>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
@using Finbuckle.MultiTenant
@using Finbuckle.MultiTenant.Abstractions
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject IMultiTenantStore<TenantInfo> _tenantStore

<!DOCTYPE html>
Expand Down
11 changes: 11 additions & 0 deletions samples/net6.0/IdentitySample/AppTenantInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using Finbuckle.MultiTenant.Abstractions;

namespace IdentitySample;

public class AppTenantInfo : ITenantInfo
{
public string? Id { get; set; }
public string? Identifier { get; set; }
public string? Name { get; set; }
public string? ConnectionString { get; set; }
}
12 changes: 8 additions & 4 deletions samples/net6.0/IdentitySample/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
using Finbuckle.MultiTenant;
using Finbuckle.MultiTenant.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;

namespace IdentitySample.Data;

public class ApplicationDbContext : MultiTenantIdentityDbContext
{
public ApplicationDbContext(ITenantInfo tenantInfo) : base(tenantInfo)
private readonly AppTenantInfo _tenantInfo;

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

public ApplicationDbContext(ITenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options)
public ApplicationDbContext(AppTenantInfo tenantInfo, DbContextOptions options) : base(tenantInfo, options)
{
_tenantInfo = tenantInfo;
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseSqlite(TenantInfo.ConnectionString ?? throw new InvalidOperationException());
optionsBuilder.UseSqlite(_tenantInfo.ConnectionString ?? throw new InvalidOperationException());
base.OnConfiguring(optionsBuilder);
}
}
4 changes: 2 additions & 2 deletions samples/net6.0/IdentitySample/Data/DesignTimeFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Refer to the solution LICENSE file for more inforation.

// using System;
using Finbuckle.MultiTenant;

using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Design;

Expand All @@ -12,7 +12,7 @@ public class SharedDesignTimeFactory : IDesignTimeDbContextFactory<ApplicationDb
{
public ApplicationDbContext CreateDbContext(string[] args)
{
var tenantInfo = new TenantInfo{ ConnectionString = "Data Source=Data/SharedIdentity.db" };
var tenantInfo = new AppTenantInfo{ ConnectionString = "Data Source=Data/SharedIdentity.db" };
var optionsBuilder = new DbContextOptionsBuilder<ApplicationDbContext>();

return new ApplicationDbContext(tenantInfo, optionsBuilder.Options);
Expand Down
9 changes: 4 additions & 5 deletions samples/net6.0/IdentitySample/IdentitySample.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
<UserSecretsId>aspnet-IdentitySample-B6EEA98C-2E15-441E-820E-F00D43BD6171</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -14,14 +13,14 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="6.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="6.0.2" />
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="6.*" />
<PackageReference Include="Finbuckle.MultiTenant.EntityFrameworkCore" Version="6.*" />
<!-- <PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="7.*" />-->
<!-- <PackageReference Include="Finbuckle.MultiTenant.EntityFrameworkCore" Version="7.*" />-->
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="6.0.2" />
</ItemGroup>

<ItemGroup>
<None Remove="Data\InitechIdentity.db-shm" />
<None Remove="Data\InitechIdentity.db-wal" />
<ProjectReference Include="..\..\..\src\Finbuckle.MultiTenant.AspNetCore\Finbuckle.MultiTenant.AspNetCore.csproj" />
<ProjectReference Include="..\..\..\src\Finbuckle.MultiTenant.EntityFrameworkCore\Finbuckle.MultiTenant.EntityFrameworkCore.csproj" />
</ItemGroup>

</Project>
20 changes: 10 additions & 10 deletions samples/net6.0/IdentitySample/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<a href="https://www.finbuckle.com/MultiTenant/Docs/Identity">documentation</a> for more details.
</p>

@if (Model.TenantInfo is null)
@if (Model.AppTenantInfo is null)
{
<h2>There is no tenant selected. Use the menu bar to select a tenant.</h2>

Expand Down Expand Up @@ -46,7 +46,7 @@
}
else
{
<h2>@Model.TenantInfo.Name</h2>
<h2>@Model.AppTenantInfo.Name</h2>
<table class="table">
<thead>
<tr>
Expand All @@ -57,20 +57,20 @@ else

<tbody>
<tr>
<td>@nameof(Model.TenantInfo.Id)</td>
<td>@Model.TenantInfo.Id</td>
<td>@nameof(Model.AppTenantInfo.Id)</td>
<td>@Model.AppTenantInfo.Id</td>
</tr>
<tr>
<td>@nameof(Model.TenantInfo.Identifier)</td>
<td>@Model.TenantInfo.Identifier</td>
<td>@nameof(Model.AppTenantInfo.Identifier)</td>
<td>@Model.AppTenantInfo.Identifier</td>
</tr>
<tr>
<td>@nameof(Model.TenantInfo.Name)</td>
<td>@Model.TenantInfo.Name</td>
<td>@nameof(Model.AppTenantInfo.Name)</td>
<td>@Model.AppTenantInfo.Name</td>
</tr>
<tr>
<td>@nameof(Model.TenantInfo.ConnectionString)</td>
<td>@Model.TenantInfo.ConnectionString</td>
<td>@nameof(Model.AppTenantInfo.ConnectionString)</td>
<td>@Model.AppTenantInfo.ConnectionString</td>
</tr>
</tbody>
</table>
Expand Down
4 changes: 2 additions & 2 deletions samples/net6.0/IdentitySample/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;

public TenantInfo? TenantInfo { get; private set; }
public AppTenantInfo? AppTenantInfo { get; private set; }

public IndexModel(ILogger<IndexModel> logger)
{
Expand All @@ -16,6 +16,6 @@ public IndexModel(ILogger<IndexModel> logger)

public void OnGet()
{
TenantInfo = HttpContext.GetMultiTenantContext<TenantInfo>()?.TenantInfo;
AppTenantInfo = HttpContext.GetMultiTenantContext<AppTenantInfo>()?.TenantInfo;
}
}
4 changes: 3 additions & 1 deletion samples/net6.0/IdentitySample/Pages/Shared/_Layout.cshtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@using Finbuckle.MultiTenant
@inject IMultiTenantStore<TenantInfo> _tenantStore
@using Finbuckle.MultiTenant.Abstractions
@using Microsoft.AspNetCore.Mvc.TagHelpers
@inject IMultiTenantStore<AppTenantInfo> _tenantStore

<!DOCTYPE html>
<html lang="en">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
@inject UserManager<IdentityUser> UserManager

<ul class="navbar-nav">
@if (Context.GetMultiTenantContext<TenantInfo>()?.TenantInfo is not null)
@if (Context.GetMultiTenantContext<AppTenantInfo>()?.TenantInfo is not null)
{
@if (SignInManager.IsSignedIn(User))
{
Expand Down
6 changes: 4 additions & 2 deletions samples/net6.0/IdentitySample/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Finbuckle.MultiTenant;
using Finbuckle.MultiTenant.Abstractions;
using IdentitySample;
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using IdentitySample.Data;
Expand All @@ -14,15 +16,15 @@
builder.Services.AddRazorPages();

// Add MultiTenant
builder.Services.AddMultiTenant<TenantInfo>()
builder.Services.AddMultiTenant<AppTenantInfo>()
.WithBasePathStrategy(options => options.RebaseAspNetCorePathBase = true)
.WithConfigurationStore()
.WithPerTenantAuthentication();

var app = builder.Build();

// Apply migrations if needed
var store = app.Services.GetRequiredService<IMultiTenantStore<TenantInfo>>();
var store = app.Services.GetRequiredService<IMultiTenantStore<AppTenantInfo>>();
foreach(var tenant in await store.GetAllAsync())
{
await using var db = new ApplicationDbContext(tenant);
Expand Down

0 comments on commit 664628f

Please sign in to comment.