Skip to content

Commit 6fb2906

Browse files
committed
gh-235 Refactor sqlite support to new projects
Signed-off-by: Victor Chang <[email protected]>
1 parent 47ffe53 commit 6fb2906

File tree

73 files changed

+416
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+416
-131
lines changed

src/Configuration/InformaticsGatewayConfiguration.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,6 @@ namespace Monai.Deploy.InformaticsGateway.Configuration
2424
/// </summary>
2525
public class InformaticsGatewayConfiguration
2626
{
27-
/// <summary>
28-
/// Name of the key for retrieve database connection string.
29-
/// </summary>
30-
public const string DatabaseConnectionStringKey = "InformaticsGatewayDatabase";
31-
3227
/// <summary>
3328
/// Represents the <c>dicom</c> section of the configuration file.
3429
/// </summary>

src/InformaticsGateway/Repositories/StorageObjectsinferenceRequest.cs renamed to src/Database/Api/IDatabaseMigrationManager.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
/*
2-
* Copyright 2021-2022 MONAI Consortium
3-
* Copyright 2019-2021 NVIDIA Corporation
2+
* Copyright 2022 MONAI Consortium
43
*
54
* Licensed under the Apache License, Version 2.0 (the "License");
65
* you may not use this file except in compliance with the License.
@@ -15,9 +14,12 @@
1514
* limitations under the License.
1615
*/
1716

18-
namespace Monai.Deploy.InformaticsGateway.Repositories
17+
using Microsoft.Extensions.Hosting;
18+
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api
1920
{
20-
public class StorageObjectsinferenceRequest
21+
public interface IDatabaseMigrationManager
2122
{
23+
IHost Migrate(IHost host);
2224
}
23-
}
25+
}

src/InformaticsGateway/Repositories/IInformaticsGatewayRepository.cs renamed to src/Database/Api/IInformaticsGatewayRepository.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17-
using System;
18-
using System.Collections.Generic;
19-
using System.Linq;
20-
using System.Threading;
21-
using System.Threading.Tasks;
2217
using Microsoft.EntityFrameworkCore.ChangeTracking;
2318

24-
namespace Monai.Deploy.InformaticsGateway.Repositories
19+
namespace Monai.Deploy.InformaticsGateway.Database.Api
2520
{
2621
public interface IInformaticsGatewayRepository<T> where T : class
2722
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!--
2+
~ Copyright 2021-2022 MONAI Consortium
3+
~
4+
~ Licensed under the Apache License, Version 2.0 (the "License");
5+
~ you may not use this file except in compliance with the License.
6+
~ You may obtain a copy of the License at
7+
~
8+
~ http://www.apache.org/licenses/LICENSE-2.0
9+
~
10+
~ Unless required by applicable law or agreed to in writing, software
11+
~ distributed under the License is distributed on an "AS IS" BASIS,
12+
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
~ See the License for the specific language governing permissions and
14+
~ limitations under the License.
15+
-->
16+
17+
<Project Sdk="Microsoft.NET.Sdk">
18+
19+
<PropertyGroup>
20+
<RootNamespace>Monai.Deploy.InformaticsGateway.Database.Repositories</RootNamespace>
21+
<TargetFramework>net6.0</TargetFramework>
22+
<ImplicitUsings>enable</ImplicitUsings>
23+
<Nullable>enable</Nullable>
24+
</PropertyGroup>
25+
26+
<ItemGroup>
27+
<Compile Remove="Test\**" />
28+
<EmbeddedResource Remove="Test\**" />
29+
<None Remove="Test\**" />
30+
</ItemGroup>
31+
32+
<ItemGroup>
33+
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
34+
</ItemGroup>
35+
36+
<ItemGroup>
37+
<ProjectReference Include="..\..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
38+
</ItemGroup>
39+
40+
</Project>

src/Database/StorageMetadataWrapper.cs renamed to src/Database/Api/StorageMetadataWrapper.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using Ardalis.GuardClauses;
2020
using Monai.Deploy.InformaticsGateway.Api.Storage;
2121

22-
namespace Monai.Deploy.InformaticsGateway.Database
22+
namespace Monai.Deploy.InformaticsGateway.Database.Api
2323
{
2424
public class StorageMetadataWrapper
2525
{
@@ -61,7 +61,7 @@ public void Update(FileStorageMetadata metadata)
6161

6262
public FileStorageMetadata GetObject()
6363
{
64-
var type = System.Type.GetType(TypeName, true);
64+
var type = Type.GetType(TypeName, true);
6565
return JsonSerializer.Deserialize(Value, type) as FileStorageMetadata;
6666
}
6767
}

src/Database/Test/Monai.Deploy.InformaticsGateway.Database.Test.csproj renamed to src/Database/Api/Test/Monai.Deploy.InformaticsGateway.Database.Api.Test.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@
3838
</ItemGroup>
3939

4040
<ItemGroup>
41-
<ProjectReference Include="..\..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
42-
<ProjectReference Include="..\Monai.Deploy.InformaticsGateway.Database.csproj" />
41+
<ProjectReference Include="..\..\..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
42+
<ProjectReference Include="..\Monai.Deploy.InformaticsGateway.Database.Api.csproj" />
4343
</ItemGroup>
4444

4545
</Project>

src/Database/Test/StorageMetadataWrapperTest.cs renamed to src/Database/Api/Test/StorageMetadataWrapperTest.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
* limitations under the License.
1515
*/
1616

17+
using Monai.Deploy.InformaticsGateway.Api.Rest;
1718
using Monai.Deploy.InformaticsGateway.Api.Storage;
19+
using Monai.Deploy.InformaticsGateway.Database.Api;
1820

1921
namespace Monai.Deploy.InformaticsGateway.Database.Test
2022
{
@@ -27,7 +29,7 @@ public void GivenAFhirFileStorageMetadataObject_WhenInitializedWithStorageMetada
2729
Guid.NewGuid().ToString(),
2830
Guid.NewGuid().ToString(),
2931
Guid.NewGuid().ToString(),
30-
Api.Rest.FhirStorageFormat.Json);
32+
FhirStorageFormat.Json);
3133
metadata.SetWorkflows("A", "B", "C");
3234

3335
var wrapper = new StorageMetadataWrapper(metadata);
File renamed without changes.

src/Database/DatabaseManager.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Microsoft.EntityFrameworkCore;
18+
using Microsoft.Extensions.Configuration;
19+
using Microsoft.Extensions.DependencyInjection;
20+
using Monai.Deploy.InformaticsGateway.Configuration;
21+
using Monai.Deploy.InformaticsGateway.Database.Api;
22+
using Monai.Deploy.InformaticsGateway.Database.Sqlite;
23+
using Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations;
24+
25+
namespace Monai.Deploy.InformaticsGateway.Database
26+
{
27+
public static class DatabaseManager
28+
{
29+
public static IServiceCollection ConfigureDatabase(this IServiceCollection services, IConfigurationSection? connectionStringConfigurationSection)
30+
{
31+
if (connectionStringConfigurationSection is null)
32+
{
33+
throw new ConfigurationException("No database connections found in configuration section 'ConnectionStrings'.");
34+
}
35+
36+
37+
var databaseType = connectionStringConfigurationSection["Type"];
38+
switch (databaseType)
39+
{
40+
case "Sqlite":
41+
services.AddScoped<IDatabaseMigrationManager, SqliteDatabaseMigrationManager>();
42+
services.AddDbContext<InformaticsGatewayContext>(
43+
options => options.UseSqlite(connectionStringConfigurationSection[SR.DatabaseConnectionStringKey]),
44+
ServiceLifetime.Transient);
45+
return services;
46+
default:
47+
throw new ConfigurationException($"Unsupported database type defined: '{databaseType}'");
48+
}
49+
}
50+
}
51+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Copyright 2022 MONAI Consortium
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
using Microsoft.Extensions.DependencyInjection;
18+
using Microsoft.Extensions.Hosting;
19+
using Monai.Deploy.InformaticsGateway.Database.Api;
20+
21+
namespace Monai.Deploy.InformaticsGateway.Database
22+
{
23+
public static class DatabaseMigrationManager
24+
{
25+
public static IHost MigrateDatabase(this IHost host)
26+
{
27+
using (var scope = host.Services.CreateScope())
28+
{
29+
scope.ServiceProvider.GetRequiredService<IDatabaseMigrationManager>()?.Migrate(host);
30+
}
31+
return host;
32+
}
33+
}
34+
}
35+

src/Database/Monai.Deploy.InformaticsGateway.Database.csproj

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,26 @@
2626
<ItemGroup>
2727
<ProjectReference Include="..\Api\Monai.Deploy.InformaticsGateway.Api.csproj" />
2828
<ProjectReference Include="..\Configuration\Monai.Deploy.InformaticsGateway.Configuration.csproj" />
29+
<ProjectReference Include="Api\Monai.Deploy.InformaticsGateway.Database.Api.csproj" />
30+
<ProjectReference Include="Sqlite\Monai.Deploy.InformaticsGateway.Database.Sqlite.csproj" />
31+
</ItemGroup>
32+
33+
<ItemGroup>
34+
<Compile Remove="Sqlite\**" />
35+
<EmbeddedResource Remove="Sqlite\**" />
36+
<None Remove="Sqlite\**" />
37+
</ItemGroup>
38+
39+
<ItemGroup>
40+
<Compile Remove="Mongo\**" />
41+
<EmbeddedResource Remove="Mongo\**" />
42+
<None Remove="Mongo\**" />
43+
</ItemGroup>
44+
45+
<ItemGroup>
46+
<Compile Remove="Api\**" />
47+
<EmbeddedResource Remove="Api\**" />
48+
<None Remove="Api\**" />
2949
</ItemGroup>
3050

3151
<ItemGroup>
@@ -43,11 +63,6 @@
4363
<PrivateAssets>All</PrivateAssets>
4464
</PackageReference>
4565
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="6.0.10" />
46-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="6.0.10">
47-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
48-
<PrivateAssets>all</PrivateAssets>
49-
</PackageReference>
50-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="6.0.10" />
5166
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
5267
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="6.0.0" />
5368
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="6.0.0" />

src/Database/DestinationApplicationEntityConfiguration.cs renamed to src/Database/Sqlite/Configurations/DestinationApplicationEntityConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
using Microsoft.EntityFrameworkCore.Metadata.Builders;
2020
using Monai.Deploy.InformaticsGateway.Api;
2121

22-
namespace Monai.Deploy.InformaticsGateway.Database
22+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2323
{
2424
internal class DestinationApplicationEntityConfiguration : IEntityTypeConfiguration<DestinationApplicationEntity>
2525
{

src/Database/InferenceRequestConfiguration.cs renamed to src/Database/Sqlite/Configurations/InferenceRequestConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
using Microsoft.EntityFrameworkCore.Metadata.Builders;
2626
using Monai.Deploy.InformaticsGateway.Api.Rest;
2727

28-
namespace Monai.Deploy.InformaticsGateway.Database
28+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2929
{
3030
internal class InferenceRequestConfiguration : IEntityTypeConfiguration<InferenceRequest>
3131
{

src/Database/MonaiApplicationEntityConfiguration.cs renamed to src/Database/Sqlite/Configurations/MonaiApplicationEntityConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
using Microsoft.EntityFrameworkCore.Metadata.Builders;
2626
using Monai.Deploy.InformaticsGateway.Api;
2727

28-
namespace Monai.Deploy.InformaticsGateway.Database
28+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2929
{
3030
internal class MonaiApplicationEntityConfiguration : IEntityTypeConfiguration<MonaiApplicationEntity>
3131
{

src/Database/PayloadConfiguration.cs renamed to src/Database/Sqlite/Configurations/PayloadConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
using Microsoft.EntityFrameworkCore.Metadata.Builders;
2525
using Monai.Deploy.InformaticsGateway.Api.Storage;
2626

27-
namespace Monai.Deploy.InformaticsGateway.Database
27+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2828
{
2929
internal class PayloadConfiguration : IEntityTypeConfiguration<Payload>
3030
{
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2021-2022 MONAI Consortium
3+
* Copyright 2019-2021 NVIDIA Corporation
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
19+
{
20+
public static class SR
21+
{
22+
/// <summary>
23+
/// Name of the key for retrieve database connection string.
24+
/// </summary>
25+
public const string DatabaseConnectionStringKey = "InformaticsGatewayDatabase";
26+
27+
}
28+
}

src/Database/SourceApplicationEntityConfiguration.cs renamed to src/Database/Sqlite/Configurations/SourceApplicationEntityConfiguration.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
using Microsoft.EntityFrameworkCore;
1919
using Monai.Deploy.InformaticsGateway.Api;
2020

21-
namespace Monai.Deploy.InformaticsGateway.Database
21+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2222
{
2323
internal class SourceApplicationEntityConfiguration : IEntityTypeConfiguration<SourceApplicationEntity>
2424
{

src/Database/StorageMetadataWrapperEntityConfiguration.cs renamed to src/Database/Sqlite/Configurations/StorageMetadataWrapperEntityConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717

1818
using Microsoft.EntityFrameworkCore;
1919
using Microsoft.EntityFrameworkCore.Metadata.Builders;
20+
using Monai.Deploy.InformaticsGateway.Database.Api;
2021

21-
namespace Monai.Deploy.InformaticsGateway.Database
22+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations
2223
{
2324
internal class StorageMetadataWrapperEntityConfiguration : IEntityTypeConfiguration<StorageMetadataWrapper>
2425
{

src/Database/InformaticsGatewayContext.cs renamed to src/Database/Sqlite/InformaticsGatewayContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
using Microsoft.EntityFrameworkCore.Diagnostics;
1919
using Microsoft.Extensions.Logging;
2020
using Monai.Deploy.InformaticsGateway.Api;
21+
using Monai.Deploy.InformaticsGateway.Database.Sqlite.Configurations;
2122

22-
namespace Monai.Deploy.InformaticsGateway.Database
23+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite
2324
{
2425
public class InformaticsGatewayContext : DbContext
2526
{

src/Database/InformaticsGatewayContextFactory.cs renamed to src/Database/Sqlite/InformaticsGatewayContextFactory.cs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@
1818
using Microsoft.EntityFrameworkCore;
1919
using Microsoft.EntityFrameworkCore.Design;
2020
using Microsoft.Extensions.Configuration;
21-
using Monai.Deploy.InformaticsGateway.Configuration;
2221

23-
namespace Monai.Deploy.InformaticsGateway.Database
22+
namespace Monai.Deploy.InformaticsGateway.Database.Sqlite
2423
{
2524
/// <summary>
2625
/// Used to EF migration.
@@ -30,13 +29,13 @@ public class InformaticsGatewayContextFactory : IDesignTimeDbContextFactory<Info
3029
public InformaticsGatewayContext CreateDbContext(string[] args)
3130
{
3231
var configuration = new ConfigurationBuilder()
33-
.SetBasePath(System.IO.Directory.GetCurrentDirectory())
32+
.SetBasePath(Directory.GetCurrentDirectory())
3433
.AddJsonFile("appsettings.json")
3534
.Build();
3635

3736
var builder = new DbContextOptionsBuilder<InformaticsGatewayContext>();
3837

39-
var connectionString = configuration.GetConnectionString(InformaticsGatewayConfiguration.DatabaseConnectionStringKey);
38+
var connectionString = configuration.GetConnectionString(Configurations.SR.DatabaseConnectionStringKey);
4039
builder.UseSqlite(connectionString);
4140

4241
return new InformaticsGatewayContext(builder.Options);

0 commit comments

Comments
 (0)