Skip to content

Commit 636c381

Browse files
authored
Refactor BaGet's architecture (loic-sharma#508)
⚠️ This pull request has several breaking changes. I apologize for any pain this may cause. Refactors several pieces of BaGet's architecture: * Renamed the `BaGet.Core.Server` project to `BaGet.Hosting`, it will contain ASP.NET Core integration bits * Unified the hosts used to run commands and the service * Updated the integration tests to use the `WebApplicationFactory` pattern * Reduced the number of namespaces
1 parent 7780b01 commit 636c381

File tree

58 files changed

+658
-596
lines changed

Some content is hidden

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

58 files changed

+658
-596
lines changed

BaGet.sln

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
3030
nuget.config = nuget.config
3131
EndProjectSection
3232
EndProject
33-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Core.Server", "src\BaGet.Core.Server\BaGet.Core.Server.csproj", "{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}"
33+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Hosting", "src\BaGet.Hosting\BaGet.Hosting.csproj", "{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}"
3434
EndProject
3535
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Database.Sqlite", "src\BaGet.Database.Sqlite\BaGet.Database.Sqlite.csproj", "{EC5E6B2C-2494-40E8-8682-080BA580DDA7}"
3636
EndProject
@@ -46,7 +46,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DDEC
4646
EndProject
4747
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Protocol.Samples.Tests", "samples\BaGet.Protocol.Samples.Tests.csproj", "{16B0D424-BB2F-4C0C-90B0-4F7955326ADF}"
4848
EndProject
49-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Aliyun", "src\BaGet.Aliyun\BaGet.Aliyun.csproj", "{9F7C4F38-D598-42D9-A9F8-962490483B18}"
49+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Aliyun", "src\BaGet.Aliyun\BaGet.Aliyun.csproj", "{9F7C4F38-D598-42D9-A9F8-962490483B18}"
5050
EndProject
5151
Global
5252
GlobalSection(SolutionConfigurationPlatforms) = preSolution

src/BaGet.Aliyun/AliyunStorageService.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Threading;
44
using System.Threading.Tasks;
55
using Aliyun.OSS;
6-
using BaGet.Aliyun.Configuration;
76
using BaGet.Core;
87
using Microsoft.Extensions.Options;
98

src/BaGet.Aliyun/Configuration/AliyunStorageOptions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.ComponentModel.DataAnnotations;
2-
using BaGet.Core;
32

4-
namespace BaGet.Aliyun.Configuration
3+
namespace BaGet.Aliyun
54
{
65
public class AliyunStorageOptions
76
{

src/BaGet.Aliyun/Extensions/ServiceCollectionExtensions.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
1-
using System;
21
using Aliyun.OSS;
3-
using BaGet.Aliyun.Configuration;
42
using Microsoft.Extensions.DependencyInjection;
53
using Microsoft.Extensions.Options;
64

7-
namespace BaGet.Aliyun.Extensions
5+
namespace BaGet.Aliyun
86
{
97
public static class ServiceCollectionExtensions
108
{

src/BaGet.Aws/Configuration/S3StorageOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel.DataAnnotations;
22
using BaGet.Core;
33

4-
namespace BaGet.Aws.Configuration
4+
namespace BaGet.Aws
55
{
66
public class S3StorageOptions
77
{

src/BaGet.Aws/Extensions/ServiceCollectionExtensions.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22
using Amazon;
33
using Amazon.Runtime;
44
using Amazon.S3;
5-
using BaGet.Aws.Configuration;
6-
using BaGet.Aws.Helpers;
75
using Microsoft.Extensions.DependencyInjection;
86
using Microsoft.Extensions.Options;
97

10-
namespace BaGet.Aws.Extensions
8+
namespace BaGet.Aws
119
{
1210
public static class ServiceCollectionExtensions
1311
{

src/BaGet.Aws/Helpers/AwsIamHelper.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Threading.Tasks;
33
using Amazon.Runtime;
44

5-
namespace BaGet.Aws.Helpers
5+
namespace BaGet.Aws
66
{
77
public static class AwsIamHelper
88
{

src/BaGet.Aws/S3StorageService.cs

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using System.Threading.Tasks;
55
using Amazon.S3;
66
using Amazon.S3.Model;
7-
using BaGet.Aws.Configuration;
87
using BaGet.Core;
98
using Microsoft.Extensions.Options;
109

src/BaGet.Azure/Extensions/IServiceCollectionExtensions.cs src/BaGet.Azure/Extensions/DependencyInjectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace BaGet.Azure
1212

1313
using TableStorageAccount = Microsoft.Azure.Cosmos.Table.CloudStorageAccount;
1414

15-
public static class IServiceCollectionExtensions
15+
public static class DependencyInjectionExtensions
1616
{
1717
public static IServiceCollection AddTableStorageService(this IServiceCollection services)
1818
{

src/BaGet.Azure/Extensions/StorageExceptionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System.Net;
22

3-
namespace BaGet.Azure.Extensions
3+
namespace BaGet.Azure
44
{
55
using StorageException = Microsoft.WindowsAzure.Storage.StorageException;
66
using TableStorageException = Microsoft.Azure.Cosmos.Table.StorageException;

src/BaGet.Azure/Storage/BlobStorageService.cs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
using System.IO;
33
using System.Threading;
44
using System.Threading.Tasks;
5-
using BaGet.Azure.Extensions;
65
using BaGet.Core;
76
using Microsoft.WindowsAzure.Storage;
87
using Microsoft.WindowsAzure.Storage.Blob;

src/BaGet.Azure/Table/TablePackageService.cs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System.Linq;
44
using System.Threading;
55
using System.Threading.Tasks;
6-
using BaGet.Azure.Extensions;
76
using BaGet.Core;
87
using Microsoft.Azure.Cosmos.Table;
98
using Microsoft.Extensions.Logging;

src/BaGet.Core/Content/DefaultPackageContentService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using BaGet.Protocol.Models;
77
using NuGet.Versioning;
88

9-
namespace BaGet.Core.Content
9+
namespace BaGet.Core
1010
{
1111
/// <summary>
1212
/// Implements the NuGet Package Content resource. Supports read-through caching.

src/BaGet.Core/Content/IPackageContentService.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using BaGet.Protocol.Models;
55
using NuGet.Versioning;
66

7-
namespace BaGet.Core.Content
7+
namespace BaGet.Core
88
{
99
/// <summary>
1010
/// The Package Content resource, used to download NuGet packages and to fetch other metadata.

src/BaGet.Core/Extensions/ServiceCollectionExtensions.cs src/BaGet.Core/Extensions/DependencyInjectionExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace BaGet.Core
66
{
7-
public static class ServiceCollectionExtensions
7+
public static class DependencyInjectionExtensions
88
{
99
public static IServiceCollection ConfigureAndValidate<TOptions>(
1010
this IServiceCollection services,

src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.ComponentModel.DataAnnotations;
22
using BaGet.Core;
33

4-
namespace BaGet.Gcp.Configuration
4+
namespace BaGet.Gcp
55
{
66
public class GoogleCloudStorageOptions : StorageOptions
77
{

src/BaGet.Gcp/Extensions/ServiceCollectionExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
using BaGet.Gcp.Services;
21
using Microsoft.Extensions.DependencyInjection;
32

4-
namespace BaGet.Gcp.Extensions
3+
namespace BaGet.Gcp
54
{
65
public static class ServiceCollectionExtensions
76
{

src/BaGet.Gcp/Services/GoogleCloudStorageService.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,11 @@
66
using System.Threading;
77
using System.Threading.Tasks;
88
using BaGet.Core;
9-
using BaGet.Gcp.Configuration;
109
using Google;
1110
using Google.Cloud.Storage.V1;
1211
using Microsoft.Extensions.Options;
1312

14-
namespace BaGet.Gcp.Services
13+
namespace BaGet.Gcp
1514
{
1615
public class GoogleCloudStorageService : IStorageService
1716
{

src/BaGet.Core.Server/BaGetUrlGenerator.cs src/BaGet.Hosting/BaGetUrlGenerator.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.AspNetCore.Routing;
55
using NuGet.Versioning;
66

7-
namespace BaGet
7+
namespace BaGet.Hosting
88
{
99
// TODO: This should validate the "Host" header against known valid values
1010
public class BaGetUrlGenerator : IUrlGenerator

src/BaGet.Core.Server/Configuration/ConfigureCorsOptions.cs src/BaGet.Hosting/Configuration/ConfigureCorsOptions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
using Microsoft.AspNetCore.Cors.Infrastructure;
22
using Microsoft.Extensions.Options;
33

4-
namespace BaGet.Configuration
4+
namespace BaGet.Hosting
55
{
66
public class ConfigureCorsOptions : IConfigureOptions<CorsOptions>
77
{
88
public const string CorsPolicy = "AllowAll";
99

1010
public void Configure(CorsOptions options)
1111
{
12+
// TODO: Consider disabling this on production builds.
1213
options.AddPolicy(
1314
CorsPolicy,
1415
builder => builder.AllowAnyOrigin()

src/BaGet.Core.Server/Configuration/ConfigureForwardedHeadersOptions.cs src/BaGet.Hosting/Configuration/ConfigureForwardedHeadersOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.AspNetCore.HttpOverrides;
33
using Microsoft.Extensions.Options;
44

5-
namespace BaGet.Configuration
5+
namespace BaGet.Hosting
66
{
77
public class ConfigureForwardedHeadersOptions : IConfigureOptions<ForwardedHeadersOptions>
88
{

src/BaGet.Core.Server/Controllers/PackageContentController.cs src/BaGet.Hosting/Controllers/PackageContentController.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
using System;
22
using System.Threading;
33
using System.Threading.Tasks;
4-
using BaGet.Core.Content;
4+
using BaGet.Core;
55
using BaGet.Protocol.Models;
66
using Microsoft.AspNetCore.Mvc;
77
using NuGet.Versioning;
88

9-
namespace BaGet.Controllers
9+
namespace BaGet.Hosting
1010
{
1111
/// <summary>
1212
/// The Package Content resource, used to download content from packages.

src/BaGet.Core.Server/Controllers/PackageMetadataController.cs src/BaGet.Hosting/Controllers/PackageMetadataController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using Microsoft.AspNetCore.Mvc;
77
using NuGet.Versioning;
88

9-
namespace BaGet.Controllers
9+
namespace BaGet.Hosting
1010
{
1111
/// <summary>
1212
/// The Package Metadata resource, used to fetch packages' information.

src/BaGet.Core.Server/Controllers/PackagePublishController.cs src/BaGet.Hosting/Controllers/PackagePublishController.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,12 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using BaGet.Core;
5-
using BaGet.Extensions;
65
using Microsoft.AspNetCore.Mvc;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.Extensions.Options;
98
using NuGet.Versioning;
109

11-
namespace BaGet.Controllers
10+
namespace BaGet.Hosting
1211
{
1312
public class PackagePublishController : Controller
1413
{

src/BaGet.Core.Server/Controllers/SearchController.cs src/BaGet.Hosting/Controllers/SearchController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using BaGet.Protocol.Models;
66
using Microsoft.AspNetCore.Mvc;
77

8-
namespace BaGet.Controllers
8+
namespace BaGet.Hosting
99
{
1010
public class SearchController : Controller
1111
{

src/BaGet.Core.Server/Controllers/ServiceIndexController.cs src/BaGet.Hosting/Controllers/ServiceIndexController.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using BaGet.Protocol.Models;
66
using Microsoft.AspNetCore.Mvc;
77

8-
namespace BaGet.Controllers
8+
namespace BaGet.Hosting
99
{
1010
/// <summary>
1111
/// The NuGet Service Index. This aids NuGet client to discover this server's services.

src/BaGet.Core.Server/Controllers/SymbolController.cs src/BaGet.Hosting/Controllers/SymbolController.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,11 @@
22
using System.Threading;
33
using System.Threading.Tasks;
44
using BaGet.Core;
5-
using BaGet.Extensions;
65
using Microsoft.AspNetCore.Mvc;
76
using Microsoft.Extensions.Logging;
87
using Microsoft.Extensions.Options;
98

10-
namespace BaGet.Controllers
9+
namespace BaGet.Hosting
1110
{
1211
public class SymbolController : Controller
1312
{

src/BaGet.Core.Server/Extensions/HttpRequestExtensions.cs src/BaGet.Hosting/Extensions/HttpRequestExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using BaGet.Core;
55
using Microsoft.AspNetCore.Http;
66

7-
namespace BaGet.Extensions
7+
namespace BaGet.Hosting
88
{
99
public static class HttpRequestExtensions
1010
{

src/BaGet.Core.Server/Extensions/IApplicationBuilderExtensions.cs src/BaGet.Hosting/Extensions/IApplicationBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System;
22
using Microsoft.AspNetCore.Builder;
33

4-
namespace BaGet.Core.Server.Extensions
4+
namespace BaGet.Hosting
55
{
66
public static class IApplicationBuilderExtensions
77
{

src/BaGet.Core.Server/Extensions/IEndpointRouteBuilderExtensions.cs src/BaGet.Hosting/Extensions/IEndpointRouteBuilderExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using Microsoft.AspNetCore.Routing;
33
using Microsoft.AspNetCore.Routing.Constraints;
44

5-
namespace BaGet.Extensions
5+
namespace BaGet.Hosting
66
{
77
public static class IEndpointRouteBuilderExtensions
88
{

src/BaGet.Core.Server/Extensions/IHostExtensions.cs src/BaGet.Hosting/Extensions/IHostExtensions.cs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
using System.Threading;
22
using System.Threading.Tasks;
33
using BaGet.Core;
4-
using Microsoft.EntityFrameworkCore;
54
using Microsoft.Extensions.DependencyInjection;
65
using Microsoft.Extensions.Hosting;
76
using Microsoft.Extensions.Options;
87

9-
namespace BaGet.Extensions
8+
namespace BaGet.Hosting
109
{
1110
public static class IHostExtensions
1211
{

src/BaGet.Core.Server/Extensions/IServiceCollectionExtensions.cs src/BaGet.Hosting/Extensions/IServiceCollectionExtensions.cs

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using BaGet.Configuration;
2-
using BaGet.Controllers;
31
using Microsoft.AspNetCore.Builder;
42
using Microsoft.AspNetCore.Cors.Infrastructure;
53
using Microsoft.AspNetCore.Http.Features;
@@ -8,7 +6,7 @@
86
using Microsoft.Extensions.Options;
97
using Newtonsoft.Json;
108

11-
namespace BaGet.Core.Server.Extensions
9+
namespace BaGet.Hosting
1210
{
1311
public static class IServiceCollectionExtensions
1412
{

src/BaGet.Core.Server/OperationCancelledMiddleware.cs src/BaGet.Hosting/OperationCancelledMiddleware.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
using Microsoft.AspNetCore.Http;
55
using Microsoft.Extensions.Logging;
66

7-
namespace BaGet
7+
namespace BaGet.Hosting
88
{
99
/// <summary>
1010
/// Captures <see cref="OperationCanceledException" /> and converts to HTTP 409 response.

src/BaGet.Core.Server/Routes.cs src/BaGet.Hosting/Routes.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
namespace BaGet
1+
namespace BaGet.Hosting
22
{
33
public class Routes
44
{

src/BaGet/BaGet.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
@@ -18,12 +18,12 @@
1818
<ProjectReference Include="..\BaGet.Aws\BaGet.Aws.csproj" />
1919
<ProjectReference Include="..\BaGet.Azure\BaGet.Azure.csproj" />
2020
<ProjectReference Include="..\BaGet.Core\BaGet.Core.csproj" />
21-
<ProjectReference Include="..\BaGet.Core.Server\BaGet.Core.Server.csproj" />
2221
<ProjectReference Include="..\BaGet.Database.MySql\BaGet.Database.MySql.csproj" />
2322
<ProjectReference Include="..\BaGet.Database.PostgreSql\BaGet.Database.PostgreSql.csproj" />
2423
<ProjectReference Include="..\BaGet.Database.Sqlite\BaGet.Database.Sqlite.csproj" />
2524
<ProjectReference Include="..\BaGet.Database.SqlServer\BaGet.Database.SqlServer.csproj" />
2625
<ProjectReference Include="..\BaGet.Gcp\BaGet.Gcp.csproj" />
26+
<ProjectReference Include="..\BaGet.Hosting\BaGet.Hosting.csproj" />
2727
<ProjectReference Include="..\BaGet.Protocol\BaGet.Protocol.csproj" />
2828
</ItemGroup>
2929

0 commit comments

Comments
 (0)