Prepare BTCPayServer for .netcore 3.0

This commit is contained in:
nicolas.dorier 2019-10-03 17:06:49 +09:00
parent 275fbc81e7
commit 4d84343a80
No known key found for this signature in database
GPG key ID: 6618763EF09186FE
9 changed files with 61 additions and 23 deletions

View file

@ -60,7 +60,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" />
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.9" Condition="'$(TargetFramework)' == 'netcoreapp2.1'" />
<PackageReference Include="TwentyTwenty.Storage" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Amazon" Version="2.11.2" />
<PackageReference Include="TwentyTwenty.Storage.Azure" Version="2.11.2" />
@ -70,6 +70,10 @@
<PackageReference Include="YamlDotNet" Version="5.2.1" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp2.1'">
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.0.0" />
</ItemGroup>
<ItemGroup>
<DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" />
</ItemGroup>

View file

@ -20,6 +20,9 @@ using System.Globalization;
using BTCPayServer.Security;
using BTCPayServer.U2F;
using BTCPayServer.Data;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
namespace BTCPayServer.Controllers
{
@ -33,7 +36,7 @@ namespace BTCPayServer.Controllers
private readonly ILogger _logger;
private readonly UrlEncoder _urlEncoder;
TokenRepository _TokenRepository;
IHostingEnvironment _Env;
IWebHostEnvironment _Env;
private readonly U2FService _u2FService;
private readonly BTCPayServerEnvironment _btcPayServerEnvironment;
StoreRepository _StoreRepository;
@ -49,7 +52,7 @@ namespace BTCPayServer.Controllers
TokenRepository tokenRepository,
BTCPayWalletProvider walletProvider,
StoreRepository storeRepository,
IHostingEnvironment env,
IWebHostEnvironment env,
U2FService u2FService,
BTCPayServerEnvironment btcPayServerEnvironment)
{

View file

@ -31,6 +31,10 @@ using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Options;
using NBitcoin;
using NBitcoin.DataEncoders;
using Newtonsoft.Json;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
namespace BTCPayServer.Controllers
{
@ -57,8 +61,7 @@ namespace BTCPayServer.Controllers
IFeeProviderFactory feeRateProvider,
LanguageService langService,
ChangellyClientProvider changellyClientProvider,
IOptions<MvcJsonOptions> mvcJsonOptions,
IHostingEnvironment env, IHttpClientFactory httpClientFactory,
IWebHostEnvironment env, IHttpClientFactory httpClientFactory,
PaymentMethodHandlerDictionary paymentMethodHandlerDictionary,
CssThemeManager cssThemeManager)
{
@ -68,7 +71,6 @@ namespace BTCPayServer.Controllers
_UserManager = userManager;
_LangService = langService;
_changellyClientProvider = changellyClientProvider;
MvcJsonOptions = mvcJsonOptions;
_TokenController = tokenController;
_WalletProvider = walletProvider;
_Env = env;
@ -95,7 +97,7 @@ namespace BTCPayServer.Controllers
UserManager<ApplicationUser> _UserManager;
private LanguageService _LangService;
private readonly ChangellyClientProvider _changellyClientProvider;
IHostingEnvironment _Env;
IWebHostEnvironment _Env;
private IHttpClientFactory _httpClientFactory;
private readonly PaymentMethodHandlerDictionary _paymentMethodHandlerDictionary;
private readonly CssThemeManager _CssThemeManager;
@ -731,7 +733,6 @@ namespace BTCPayServer.Controllers
}
public string GeneratedPairingCode { get; set; }
public IOptions<MvcJsonOptions> MvcJsonOptions { get; }
[HttpGet]
[Route("/api-tokens")]

View file

@ -44,7 +44,7 @@ namespace BTCPayServer.Controllers
public ExplorerClientProvider ExplorerClientProvider { get; }
private readonly UserManager<ApplicationUser> _userManager;
private readonly IOptions<MvcJsonOptions> _mvcJsonOptions;
private readonly JsonSerializerSettings _serializerSettings;
private readonly NBXplorerDashboard _dashboard;
private readonly IFeeProviderFactory _feeRateProvider;
@ -59,7 +59,7 @@ namespace BTCPayServer.Controllers
CurrencyNameTable currencyTable,
BTCPayNetworkProvider networkProvider,
UserManager<ApplicationUser> userManager,
IOptions<MvcJsonOptions> mvcJsonOptions,
MvcNewtonsoftJsonOptions mvcJsonOptions,
NBXplorerDashboard dashboard,
RateFetcher rateProvider,
ExplorerClientProvider explorerProvider,
@ -72,7 +72,7 @@ namespace BTCPayServer.Controllers
RateFetcher = rateProvider;
NetworkProvider = networkProvider;
_userManager = userManager;
_mvcJsonOptions = mvcJsonOptions;
_serializerSettings = mvcJsonOptions.SerializerSettings;
_dashboard = dashboard;
ExplorerClientProvider = explorerProvider;
_feeRateProvider = feeRateProvider;
@ -795,7 +795,7 @@ namespace BTCPayServer.Controllers
if (result != null)
{
UTF8Encoding UTF8NOBOM = new UTF8Encoding(false);
var bytes = UTF8NOBOM.GetBytes(JsonConvert.SerializeObject(result, _mvcJsonOptions.Value.SerializerSettings));
var bytes = UTF8NOBOM.GetBytes(JsonConvert.SerializeObject(result, _serializerSettings));
await webSocket.SendAsync(new ArraySegment<byte>(bytes), WebSocketMessageType.Text, true, new CancellationTokenSource(2000).Token);
}
}

View file

@ -60,6 +60,12 @@ namespace BTCPayServer.Hosting
{
public static IServiceCollection AddBTCPayServer(this IServiceCollection services, IConfiguration configuration)
{
#if NETCOREAPP21
services.AddSingleton<IConfigureOptions<MvcJsonOptions>, MVCConfigureOptions>();
services.AddSingleton<MvcNewtonsoftJsonOptions>();
#else
services.AddSingleton<MvcNewtonsoftJsonOptions>(o => o.GetRequiredService<IOptions<MvcNewtonsoftJsonOptions>>().Value);
#endif
services.AddDbContext<ApplicationDbContext>((provider, o) =>
{
var factory = provider.GetRequiredService<ApplicationDbContextFactory>();
@ -329,5 +335,13 @@ namespace BTCPayServer.Hosting
}
}
#if NETCOREAPP21
class MVCConfigureOptions : IConfigureOptions<MvcJsonOptions>
{
public void Configure(MvcJsonOptions options)
{
new Serializer(null).ConfigureSerializer(options.SerializerSettings);
}
}
#endif
}

View file

@ -6,7 +6,12 @@ using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using BundlerMinifier.TagHelpers;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#else
using Newtonsoft.Json.Serialization;
using Microsoft.AspNetCore.Hosting;
#endif
using Newtonsoft.Json.Linq;
namespace BTCPayServer.Hosting
@ -15,7 +20,7 @@ namespace BTCPayServer.Hosting
{
BundleProvider _InnerProvider;
Lazy<Dictionary<string, Bundle>> _BundlesByName;
public ResourceBundleProvider(IHostingEnvironment hosting, BundleOptions options)
public ResourceBundleProvider(IWebHostEnvironment hosting, BundleOptions options)
{
if (options.UseBundles)
{

View file

@ -1,4 +1,7 @@
using Microsoft.AspNetCore.Hosting;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
using Microsoft.AspNetCore.Builder;
using System;
using Microsoft.Extensions.DependencyInjection;
@ -31,13 +34,13 @@ namespace BTCPayServer.Hosting
{
public class Startup
{
public Startup(IConfiguration conf, IHostingEnvironment env, ILoggerFactory loggerFactory)
public Startup(IConfiguration conf, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
Configuration = conf;
_Env = env;
LoggerFactory = loggerFactory;
}
IHostingEnvironment _Env;
IWebHostEnvironment _Env;
public IConfiguration Configuration
{
get; set;
@ -199,7 +202,7 @@ namespace BTCPayServer.Hosting
public void Configure(
IApplicationBuilder app,
IHostingEnvironment env,
IWebHostEnvironment env,
IServiceProvider prov,
BTCPayServerOptions options,
ILoggerFactory loggerFactory)
@ -218,7 +221,7 @@ namespace BTCPayServer.Hosting
}
}
private static void ConfigureCore(IApplicationBuilder app, IHostingEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
private static void ConfigureCore(IApplicationBuilder app, IWebHostEnvironment env, IServiceProvider prov, ILoggerFactory loggerFactory, BTCPayServerOptions options)
{
if (env.IsDevelopment())
{

View file

@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Hosting;
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
@ -8,6 +7,10 @@ using System.Text;
using NBXplorer;
using NBitcoin;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Hosting;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#endif
namespace BTCPayServer.Services
{
@ -15,7 +18,7 @@ namespace BTCPayServer.Services
{
IHttpContextAccessor httpContext;
TorServices torServices;
public BTCPayServerEnvironment(IHostingEnvironment env, BTCPayNetworkProvider provider, IHttpContextAccessor httpContext, TorServices torServices)
public BTCPayServerEnvironment(IWebHostEnvironment env, BTCPayNetworkProvider provider, IHttpContextAccessor httpContext, TorServices torServices)
{
this.httpContext = httpContext;
Version = typeof(BTCPayServerEnvironment).GetTypeInfo().Assembly.GetCustomAttribute<AssemblyFileVersionAttribute>().Version;
@ -28,7 +31,7 @@ namespace BTCPayServer.Services
NetworkType = provider.NetworkType;
this.torServices = torServices;
}
public IHostingEnvironment Environment
public IWebHostEnvironment Environment
{
get; set;
}

View file

@ -6,6 +6,11 @@ using Microsoft.Extensions.Hosting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Serialization;
#if NETCOREAPP21
using IWebHostEnvironment = Microsoft.AspNetCore.Hosting.IHostingEnvironment;
#else
using Microsoft.AspNetCore.Hosting;
#endif
namespace BTCPayServer.Services
{
@ -27,7 +32,7 @@ namespace BTCPayServer.Services
{
private readonly Language[] _languages;
public LanguageService(IHostingEnvironment environment)
public LanguageService(IWebHostEnvironment environment)
{
var path = (environment as HostingEnvironment)?.WebRootPath;
if (string.IsNullOrEmpty(path))