Skip to content

Commit

Permalink
updated samples to .NET 8.0
Browse files Browse the repository at this point in the history
closes #27
  • Loading branch information
JohnCampionJr committed Jun 3, 2024
1 parent c2696da commit b91bd56
Show file tree
Hide file tree
Showing 84 changed files with 85 additions and 179 deletions.
12 changes: 6 additions & 6 deletions Finbuckle.MultiTenant.MongoFramework.sln
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataIsolationSample", "exam
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoTenantStoreSample", "examples\NET6\MongoTenantStoreSample\MongoTenantStoreSample.csproj", "{4E3D2992-1195-4AFF-B258-A3FBE85EE320}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".NET 7.0", ".NET 7.0", "{A5F851CB-B364-4EF6-8C0F-BE9AC268AF8A}"
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".NET 8.0", ".NET 8.0", "{A5F851CB-B364-4EF6-8C0F-BE9AC268AF8A}"
ProjectSection(SolutionItems) = preProject
examples\NET7\Directory.Build.props = examples\NET7\Directory.Build.props
examples\NET8\Directory.Build.props = examples\NET8\Directory.Build.props
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthenticationSample", "examples\NET7\AuthenticationSample\AuthenticationSample.csproj", "{2291A189-2241-4A3B-A86A-58A86C98E3E9}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "AuthenticationSample", "examples\NET8\AuthenticationSample\AuthenticationSample.csproj", "{2291A189-2241-4A3B-A86A-58A86C98E3E9}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CombinedSample", "examples\NET7\CombinedSample\CombinedSample.csproj", "{B384B273-21B6-4060-A133-09E71C75B6C0}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CombinedSample", "examples\NET8\CombinedSample\CombinedSample.csproj", "{B384B273-21B6-4060-A133-09E71C75B6C0}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataIsolationSample", "examples\NET7\DataIsolationSample\DataIsolationSample.csproj", "{649724B7-D079-4389-959A-506755FFE8AF}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DataIsolationSample", "examples\NET8\DataIsolationSample\DataIsolationSample.csproj", "{649724B7-D079-4389-959A-506755FFE8AF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoTenantStoreSample", "examples\NET7\MongoTenantStoreSample\MongoTenantStoreSample.csproj", "{173D0BF0-8F64-4703-9594-734557B3832E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MongoTenantStoreSample", "examples\NET8\MongoTenantStoreSample\MongoTenantStoreSample.csproj", "{173D0BF0-8F64-4703-9594-734557B3832E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
39 changes: 0 additions & 39 deletions examples/NET7/AuthenticationSample/ApplicationStartedService.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="7.0.8" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="8.0.6" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="8.0.6" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Collections.Generic;
using System.Collections.Generic;
using AuthenticationSample;
using AuthenticationSample.Data;
using Finbuckle.Utilities.AspNetCore;
Expand Down Expand Up @@ -39,10 +35,10 @@
.WithMongoFrameworkStore(builder.Configuration.GetConnectionString("TenantStoreConnection"))
.WithPerTenantAuthentication();

//NOTE: this service will be called by the runtime when application is actually started
services.AddSingleton<IHostedService, ApplicationStartedService>();

var app = builder.Build();

await SeedService.Seed(app);

if (app.Environment.IsDevelopment())
{
app.UseDeveloperExceptionPage();
Expand All @@ -63,8 +59,6 @@
app.UseAuthentication();
app.UseAuthorization();

app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
app.MapRazorPages();

app.Run();
31 changes: 31 additions & 0 deletions examples/NET8/AuthenticationSample/SeedService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
using System.Linq;
using System.Threading.Tasks;
using Finbuckle.MultiTenant;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

namespace AuthenticationSample;

/// <summary>
/// Seed the database the multi-tenant store we'll need.
/// When application has started
/// </summary>
public static class SeedService
{
public static async Task Seed(WebApplication app)
{
using var scope = app.Services.CreateScope();

var store = scope.ServiceProvider.GetRequiredService<IMultiTenantStore<SampleTenantInfo>>();
await SetupStore(store);
}

private static async Task SetupStore(IMultiTenantStore<SampleTenantInfo> store)
{
if (store.GetAllAsync().Result.Any()) return;

await store.TryAddAsync(new SampleTenantInfo { Id = "tenant-finbuckle-d043favoiaw", Identifier = "finbuckle", Name = "Finbuckle" });
await store.TryAddAsync(new SampleTenantInfo { Id = "tenant-initech-341ojadsfa", Identifier = "initech", Name = "Initech LLC", ConnectionString = "mongodb://localhost/samples-tenant-initech" });
await store.TryAddAsync(new SampleTenantInfo { Id = "tenant-megacorp-g754dafg", Identifier = "megacorp", Name = "MegaCorp Inc" });
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"Microsoft.AspNetCore": "Warning"
}
},
"AllowedHosts": "*"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using CombinedSample;
using CombinedSample;
using DataIsolationSample.Data;
using Finbuckle.MultiTenant;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

var builder = WebApplication.CreateBuilder(args);

Expand All @@ -29,12 +24,10 @@
// these vary by tenant.
services.AddMongoDbContext<ToDoDbContext>();

//NOTE: this service will be called by the runtime when application is actually started
services.AddSingleton<IHostedService, ApplicationStartedService>();


var app = builder.Build();

await SeedService.Seed(app);

if (app.Environment.EnvironmentName == "Development")
{
app.UseDeveloperExceptionPage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Threading;
using System.Linq;
using System.Threading.Tasks;
using DataIsolationSample.Data;
using DataIsolationSample.Models;
using Finbuckle.MultiTenant;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.DependencyInjection;
using MongoFramework;

namespace CombinedSample;
Expand All @@ -19,32 +14,19 @@ namespace CombinedSample;
/// Seed the database the multi-tenant store we'll need.
/// When application has started
/// </summary>
public class ApplicationStartedService : IHostedService
public static class SeedService
{
private readonly IMultiTenantStore<MongoTenantInfo> _store;
private readonly IConfiguration _config;

public ApplicationStartedService(IMultiTenantStore<MongoTenantInfo> store, IConfiguration config)
{
_store = store;
_config = config;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await SetupStore(_store);
await SetupDb(_store, _config);
}

public Task StopAsync(CancellationToken cancellationToken)
public static async Task Seed(WebApplication app)
{
// Execute code here that you want to run when the application stops
Console.WriteLine("Application is stopping.");
var config = app.Services.GetRequiredService<IConfiguration>();
using var scope = app.Services.CreateScope();

return Task.CompletedTask;
var store = scope.ServiceProvider.GetRequiredService<IMultiTenantStore<MongoTenantInfo>>();
await SetupStore(store);
await SetupDb(store, config);
}

private async Task SetupStore(IMultiTenantStore<MongoTenantInfo> store)
private static async Task SetupStore(IMultiTenantStore<MongoTenantInfo> store)
{
if (store.GetAllAsync().Result.Any()) return;

Expand All @@ -53,7 +35,7 @@ private async Task SetupStore(IMultiTenantStore<MongoTenantInfo> store)
await store.TryAddAsync(new MongoTenantInfo { Id = "tenant-megacorp-g754dafg", Identifier = "megacorp", Name = "MegaCorp Inc" });
}

private async Task SetupDb(IMultiTenantStore<MongoTenantInfo> store, IConfiguration config)
private static async Task SetupDb(IMultiTenantStore<MongoTenantInfo> store, IConfiguration config)
{
var ti = store.TryGetByIdentifierAsync("finbuckle").Result;
if (ti.ConnectionString is null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using MongoFramework;
using MongoTenantStoreSample;


var builder = WebApplication.CreateBuilder(args);
Expand All @@ -29,12 +30,10 @@
// these vary by tenant.
services.AddMongoDbContext<ToDoDbContext>();

//NOTE: this service will be called by the runtime when application is actually started
services.AddSingleton<IHostedService, ApplicationStartedService>();


var app = builder.Build();

await SeedService.Seed();

if (app.Environment.EnvironmentName == "Development")
{
app.UseDeveloperExceptionPage();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,59 +1,24 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System;
using System.Linq;
using System.Threading;
using System.Linq;
using System.Threading.Tasks;
using DataIsolationSample.Data;
using DataIsolationSample.Models;
using Finbuckle.MultiTenant;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using MongoFramework;

namespace DataIsolationSample;
namespace MongoTenantStoreSample;

/// <summary>
/// Seed the database the multi-tenant store we'll need.
/// When application has started
/// </summary>
public class ApplicationStartedService : IHostedService
public static class SeedService
{
private readonly IMultiTenantStore<MongoTenantInfo> _store;
private readonly IConfiguration _config;

public ApplicationStartedService(IMultiTenantStore<MongoTenantInfo> store, IConfiguration config)
{
_store = store;
_config = config;
}

public async Task StartAsync(CancellationToken cancellationToken)
{
await SetupStore(_store);
await SetupDb(_store, _config);
}

public Task StopAsync(CancellationToken cancellationToken)
public static async Task Seed()
{
// Execute code here that you want to run when the application stops
Console.WriteLine("Application is stopping.");

return Task.CompletedTask;
await SetupDb();
}

private async Task SetupStore(IMultiTenantStore<MongoTenantInfo> store)
{
if (store.GetAllAsync().Result.Any()) return;

await store.TryAddAsync(new MongoTenantInfo { Id = "tenant-finbuckle-d043favoiaw", Identifier = "finbuckle", Name = "Finbuckle" });
await store.TryAddAsync(new MongoTenantInfo { Id = "tenant-initech-341ojadsfa", Identifier = "initech", Name = "Initech LLC", ConnectionString = "mongodb://localhost/samples-tenant-initech" });
await store.TryAddAsync(new MongoTenantInfo { Id = "tenant-megacorp-g754dafg", Identifier = "megacorp", Name = "MegaCorp Inc" });
}

private async Task SetupDb(IMultiTenantStore<MongoTenantInfo> store, IConfiguration config)

private static async Task SetupDb()
{
var ti = new TenantInfo { Id = "tenant-finbuckle-d043favoiaw", ConnectionString = "mongodb://localhost/isolation-test", Identifier = "finbuckle" };
var conn = new MongoPerTenantConnection(ti);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
<Project>


<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<TargetFramework>net8.0</TargetFramework>
</PropertyGroup>
<PropertyGroup>
<NoWarn>ASP0014</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="6.10.0" />
<PackageReference Include="MongoFramework.AspNetCore.Identity" Version="0.4.0" /> <!-- AddMongoDbContext -->
<PackageReference Include="Finbuckle.MultiTenant.AspNetCore" Version="6.11.1" />
<PackageReference Include="MongoFramework.AspNetCore.Identity" Version="0.5.0" /> <!-- AddMongoDbContext -->
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
<ItemGroup>
<PackageReference Update="Finbuckle.MultiTenant.AspNetCore" Version="6.11.1" />
</ItemGroup>
</Project>
</Project>
Loading

0 comments on commit b91bd56

Please sign in to comment.