Skip to content

Commit

Permalink
Refactor BaGet's architecture (loic-sharma#508)
Browse files Browse the repository at this point in the history
⚠️ 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
  • Loading branch information
loic-sharma authored May 4, 2020
1 parent 7780b01 commit 636c381
Show file tree
Hide file tree
Showing 58 changed files with 658 additions and 596 deletions.
4 changes: 2 additions & 2 deletions BaGet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
nuget.config = nuget.config
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Core.Server", "src\BaGet.Core.Server\BaGet.Core.Server.csproj", "{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Hosting", "src\BaGet.Hosting\BaGet.Hosting.csproj", "{D68B56AC-98DD-4DA7-B4F8-1243538A8A5C}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Database.Sqlite", "src\BaGet.Database.Sqlite\BaGet.Database.Sqlite.csproj", "{EC5E6B2C-2494-40E8-8682-080BA580DDA7}"
EndProject
Expand All @@ -46,7 +46,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "samples", "samples", "{DDEC
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Protocol.Samples.Tests", "samples\BaGet.Protocol.Samples.Tests.csproj", "{16B0D424-BB2F-4C0C-90B0-4F7955326ADF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BaGet.Aliyun", "src\BaGet.Aliyun\BaGet.Aliyun.csproj", "{9F7C4F38-D598-42D9-A9F8-962490483B18}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BaGet.Aliyun", "src\BaGet.Aliyun\BaGet.Aliyun.csproj", "{9F7C4F38-D598-42D9-A9F8-962490483B18}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand Down
1 change: 0 additions & 1 deletion src/BaGet.Aliyun/AliyunStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Threading;
using System.Threading.Tasks;
using Aliyun.OSS;
using BaGet.Aliyun.Configuration;
using BaGet.Core;
using Microsoft.Extensions.Options;

Expand Down
3 changes: 1 addition & 2 deletions src/BaGet.Aliyun/Configuration/AliyunStorageOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System.ComponentModel.DataAnnotations;
using BaGet.Core;

namespace BaGet.Aliyun.Configuration
namespace BaGet.Aliyun
{
public class AliyunStorageOptions
{
Expand Down
4 changes: 1 addition & 3 deletions src/BaGet.Aliyun/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using System;
using Aliyun.OSS;
using BaGet.Aliyun.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace BaGet.Aliyun.Extensions
namespace BaGet.Aliyun
{
public static class ServiceCollectionExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Aws/Configuration/S3StorageOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using BaGet.Core;

namespace BaGet.Aws.Configuration
namespace BaGet.Aws
{
public class S3StorageOptions
{
Expand Down
4 changes: 1 addition & 3 deletions src/BaGet.Aws/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,10 @@
using Amazon;
using Amazon.Runtime;
using Amazon.S3;
using BaGet.Aws.Configuration;
using BaGet.Aws.Helpers;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Options;

namespace BaGet.Aws.Extensions
namespace BaGet.Aws
{
public static class ServiceCollectionExtensions
{
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Aws/Helpers/AwsIamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using System.Threading.Tasks;
using Amazon.Runtime;

namespace BaGet.Aws.Helpers
namespace BaGet.Aws
{
public static class AwsIamHelper
{
Expand Down
1 change: 0 additions & 1 deletion src/BaGet.Aws/S3StorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using System.Threading.Tasks;
using Amazon.S3;
using Amazon.S3.Model;
using BaGet.Aws.Configuration;
using BaGet.Core;
using Microsoft.Extensions.Options;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace BaGet.Azure

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

public static class IServiceCollectionExtensions
public static class DependencyInjectionExtensions
{
public static IServiceCollection AddTableStorageService(this IServiceCollection services)
{
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Azure/Extensions/StorageExceptionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Net;

namespace BaGet.Azure.Extensions
namespace BaGet.Azure
{
using StorageException = Microsoft.WindowsAzure.Storage.StorageException;
using TableStorageException = Microsoft.Azure.Cosmos.Table.StorageException;
Expand Down
1 change: 0 additions & 1 deletion src/BaGet.Azure/Storage/BlobStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using BaGet.Azure.Extensions;
using BaGet.Core;
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Blob;
Expand Down
1 change: 0 additions & 1 deletion src/BaGet.Azure/Table/TablePackageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BaGet.Azure.Extensions;
using BaGet.Core;
using Microsoft.Azure.Cosmos.Table;
using Microsoft.Extensions.Logging;
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Core/Content/DefaultPackageContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using BaGet.Protocol.Models;
using NuGet.Versioning;

namespace BaGet.Core.Content
namespace BaGet.Core
{
/// <summary>
/// Implements the NuGet Package Content resource. Supports read-through caching.
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Core/Content/IPackageContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using BaGet.Protocol.Models;
using NuGet.Versioning;

namespace BaGet.Core.Content
namespace BaGet.Core
{
/// <summary>
/// The Package Content resource, used to download NuGet packages and to fetch other metadata.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace BaGet.Core
{
public static class ServiceCollectionExtensions
public static class DependencyInjectionExtensions
{
public static IServiceCollection ConfigureAndValidate<TOptions>(
this IServiceCollection services,
Expand Down
2 changes: 1 addition & 1 deletion src/BaGet.Gcp/Configuration/GoogleCloudStorageOptions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System.ComponentModel.DataAnnotations;
using BaGet.Core;

namespace BaGet.Gcp.Configuration
namespace BaGet.Gcp
{
public class GoogleCloudStorageOptions : StorageOptions
{
Expand Down
3 changes: 1 addition & 2 deletions src/BaGet.Gcp/Extensions/ServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using BaGet.Gcp.Services;
using Microsoft.Extensions.DependencyInjection;

namespace BaGet.Gcp.Extensions
namespace BaGet.Gcp
{
public static class ServiceCollectionExtensions
{
Expand Down
3 changes: 1 addition & 2 deletions src/BaGet.Gcp/Services/GoogleCloudStorageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core;
using BaGet.Gcp.Configuration;
using Google;
using Google.Cloud.Storage.V1;
using Microsoft.Extensions.Options;

namespace BaGet.Gcp.Services
namespace BaGet.Gcp
{
public class GoogleCloudStorageService : IStorageService
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Routing;
using NuGet.Versioning;

namespace BaGet
namespace BaGet.Hosting
{
// TODO: This should validate the "Host" header against known valid values
public class BaGetUrlGenerator : IUrlGenerator
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.Extensions.Options;

namespace BaGet.Configuration
namespace BaGet.Hosting
{
public class ConfigureCorsOptions : IConfigureOptions<CorsOptions>
{
public const string CorsPolicy = "AllowAll";

public void Configure(CorsOptions options)
{
// TODO: Consider disabling this on production builds.
options.AddPolicy(
CorsPolicy,
builder => builder.AllowAnyOrigin()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.HttpOverrides;
using Microsoft.Extensions.Options;

namespace BaGet.Configuration
namespace BaGet.Hosting
{
public class ConfigureForwardedHeadersOptions : IConfigureOptions<ForwardedHeadersOptions>
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core.Content;
using BaGet.Core;
using BaGet.Protocol.Models;
using Microsoft.AspNetCore.Mvc;
using NuGet.Versioning;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
/// <summary>
/// The Package Content resource, used to download content from packages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using Microsoft.AspNetCore.Mvc;
using NuGet.Versioning;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
/// <summary>
/// The Package Metadata resource, used to fetch packages' information.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core;
using BaGet.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using NuGet.Versioning;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
public class PackagePublishController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using BaGet.Protocol.Models;
using Microsoft.AspNetCore.Mvc;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
public class SearchController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
using BaGet.Protocol.Models;
using Microsoft.AspNetCore.Mvc;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
/// <summary>
/// The NuGet Service Index. This aids NuGet client to discover this server's services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core;
using BaGet.Extensions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;

namespace BaGet.Controllers
namespace BaGet.Hosting
{
public class SymbolController : Controller
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using BaGet.Core;
using Microsoft.AspNetCore.Http;

namespace BaGet.Extensions
namespace BaGet.Hosting
{
public static class HttpRequestExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using System;
using Microsoft.AspNetCore.Builder;

namespace BaGet.Core.Server.Extensions
namespace BaGet.Hosting
{
public static class IApplicationBuilderExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using Microsoft.AspNetCore.Routing;
using Microsoft.AspNetCore.Routing.Constraints;

namespace BaGet.Extensions
namespace BaGet.Hosting
{
public static class IEndpointRouteBuilderExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
using System.Threading;
using System.Threading.Tasks;
using BaGet.Core;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Options;

namespace BaGet.Extensions
namespace BaGet.Hosting
{
public static class IHostExtensions
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using BaGet.Configuration;
using BaGet.Controllers;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Cors.Infrastructure;
using Microsoft.AspNetCore.Http.Features;
Expand All @@ -8,7 +6,7 @@
using Microsoft.Extensions.Options;
using Newtonsoft.Json;

namespace BaGet.Core.Server.Extensions
namespace BaGet.Hosting
{
public static class IServiceCollectionExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;

namespace BaGet
namespace BaGet.Hosting
{
/// <summary>
/// Captures <see cref="OperationCanceledException" /> and converts to HTTP 409 response.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace BaGet
namespace BaGet.Hosting
{
public class Routes
{
Expand Down
4 changes: 2 additions & 2 deletions src/BaGet/BaGet.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
Expand All @@ -18,12 +18,12 @@
<ProjectReference Include="..\BaGet.Aws\BaGet.Aws.csproj" />
<ProjectReference Include="..\BaGet.Azure\BaGet.Azure.csproj" />
<ProjectReference Include="..\BaGet.Core\BaGet.Core.csproj" />
<ProjectReference Include="..\BaGet.Core.Server\BaGet.Core.Server.csproj" />
<ProjectReference Include="..\BaGet.Database.MySql\BaGet.Database.MySql.csproj" />
<ProjectReference Include="..\BaGet.Database.PostgreSql\BaGet.Database.PostgreSql.csproj" />
<ProjectReference Include="..\BaGet.Database.Sqlite\BaGet.Database.Sqlite.csproj" />
<ProjectReference Include="..\BaGet.Database.SqlServer\BaGet.Database.SqlServer.csproj" />
<ProjectReference Include="..\BaGet.Gcp\BaGet.Gcp.csproj" />
<ProjectReference Include="..\BaGet.Hosting\BaGet.Hosting.csproj" />
<ProjectReference Include="..\BaGet.Protocol\BaGet.Protocol.csproj" />
</ItemGroup>

Expand Down
Loading

0 comments on commit 636c381

Please sign in to comment.