diff --git a/.circleci/config.yml b/.circleci/config.yml index 99ecd91..5866c14 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -2,7 +2,7 @@ version: 2.1 executors: dotnet: docker: - - image: mcr.microsoft.com/dotnet/core/sdk:2.2 + - image: mcr.microsoft.com/dotnet/core/sdk:3.0 environment: DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true NUGET_XMLDOC_MODE: skip diff --git a/ReadMe.md b/ReadMe.md index 4772a2d..983d7ac 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -422,7 +422,7 @@ builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Loc // set the host configuration builder.ConfigureHostConfiguration(config => { - config.AddEnvironmentVariables(prefix: "NETCORE_"); + config.AddEnvironmentVariables(prefix: "DOTNET_"); config.AddInMemoryCollection(new[] { new KeyValuePair(HostDefaults.ApplicationKey, Assembly.GetExecutingAssembly().GetName().Name) }); }); diff --git a/sandbox/MultiContainedApp/MultiContainedApp.csproj b/sandbox/MultiContainedApp/MultiContainedApp.csproj index 72d8504..eb52b4a 100644 --- a/sandbox/MultiContainedApp/MultiContainedApp.csproj +++ b/sandbox/MultiContainedApp/MultiContainedApp.csproj @@ -6,12 +6,6 @@ 7.3 - - - - - - diff --git a/sandbox/SingleContainedApp/SingleContainedApp.csproj b/sandbox/SingleContainedApp/SingleContainedApp.csproj index d566b2d..4e3f186 100644 --- a/sandbox/SingleContainedApp/SingleContainedApp.csproj +++ b/sandbox/SingleContainedApp/SingleContainedApp.csproj @@ -16,12 +16,6 @@ - - - - - - diff --git a/sandbox/SingleContainedAppWithConfig/SingleContainedAppWithConfig.csproj b/sandbox/SingleContainedAppWithConfig/SingleContainedAppWithConfig.csproj index 76b5c98..0292440 100644 --- a/sandbox/SingleContainedAppWithConfig/SingleContainedAppWithConfig.csproj +++ b/sandbox/SingleContainedAppWithConfig/SingleContainedAppWithConfig.csproj @@ -28,13 +28,6 @@ - - - - - - - diff --git a/sandbox/WebHostingApp/WebHostingApp.csproj b/sandbox/WebHostingApp/WebHostingApp.csproj index 68ad23c..e4caf7b 100644 --- a/sandbox/WebHostingApp/WebHostingApp.csproj +++ b/sandbox/WebHostingApp/WebHostingApp.csproj @@ -2,16 +2,16 @@ Exe - netcoreapp2.1 + netcoreapp3.0 7.3 - - - - + + + + diff --git a/src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs b/src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs index 894c4b8..d314503 100644 --- a/src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs +++ b/src/MicroBatchFramework.WebHosting/BatchEngineSwaggerMiddleware.cs @@ -26,7 +26,7 @@ public BatchEngineSwaggerMiddleware(RequestDelegate next, TargetBatchTypeCollect this.options = options; } - public Task Invoke(HttpContext httpContext) + public async Task Invoke(HttpContext httpContext) { // reference embedded resouces const string prefix = "MicroBatchFramework.WebHosting.Swagger.SwaggerUI."; @@ -42,8 +42,8 @@ public Task Invoke(HttpContext httpContext) var bytes = builder.BuildSwaggerJson(); httpContext.Response.Headers["Content-Type"] = new[] { "application/json" }; httpContext.Response.StatusCode = 200; - httpContext.Response.Body.Write(bytes, 0, bytes.Length); - return EmptyTask; + await httpContext.Response.Body.WriteAsync(bytes, 0, bytes.Length); + return; } var myAssembly = typeof(BatchEngineSwaggerMiddleware).GetTypeInfo().Assembly; @@ -55,13 +55,14 @@ public Task Invoke(HttpContext httpContext) if (stream == null) { // not found, standard request. - return next(httpContext); + await next(httpContext); + return; } httpContext.Response.Headers["Content-Type"] = new[] { mediaType }; httpContext.Response.StatusCode = 200; var response = httpContext.Response.Body; - stream.CopyTo(response); + await stream.CopyToAsync(response); } else { @@ -74,7 +75,7 @@ public Task Invoke(HttpContext httpContext) { using (var ms = new MemoryStream()) { - stream.CopyTo(ms); + await stream.CopyToAsync(ms); bytes = options.ResolveCustomResource(path, ms.ToArray()); } } @@ -82,18 +83,16 @@ public Task Invoke(HttpContext httpContext) if (bytes == null) { // not found, standard request. - return next(httpContext); + await next(httpContext); + return; } httpContext.Response.Headers["Content-Type"] = new[] { mediaType }; httpContext.Response.StatusCode = 200; var response = httpContext.Response.Body; - response.Write(bytes, 0, bytes.Length); + await response.WriteAsync(bytes, 0, bytes.Length); } } - - - return EmptyTask; } static string GetMediaType(string path) diff --git a/src/MicroBatchFramework.WebHosting/MicroBatchFramework.WebHosting.csproj b/src/MicroBatchFramework.WebHosting/MicroBatchFramework.WebHosting.csproj index efb372b..e7699f9 100644 --- a/src/MicroBatchFramework.WebHosting/MicroBatchFramework.WebHosting.csproj +++ b/src/MicroBatchFramework.WebHosting/MicroBatchFramework.WebHosting.csproj @@ -1,7 +1,7 @@  - netstandard2.0 + netcoreapp3.0 @@ -9,8 +9,11 @@ - - + + + + + diff --git a/src/MicroBatchFramework/BatchHost.cs b/src/MicroBatchFramework/BatchHost.cs index d86e53c..4b5aae3 100644 --- a/src/MicroBatchFramework/BatchHost.cs +++ b/src/MicroBatchFramework/BatchHost.cs @@ -7,6 +7,7 @@ using System.IO; using System.Reflection; using System.Collections.Generic; +using System.Linq; namespace MicroBatchFramework { @@ -21,7 +22,7 @@ public static class BatchHost /// /// /// The following defaults are applied to the returned : - /// set the to the NETCORE_ENVIRONMENT, + /// set the to the DOTNET_ENVIRONMENT, /// load from 'appsettings.json' and 'appsettings.[].json', /// load from User Secrets when is 'Development' using the entry assembly, /// load from environment variables, @@ -35,7 +36,7 @@ public static class BatchHost /// /// /// The following defaults are applied to the returned : - /// set the to the NETCORE_ENVIRONMENT, + /// set the to the DOTNET_ENVIRONMENT, /// load from 'appsettings.json' and 'appsettings.[].json', /// load from User Secrets when is 'Development' using the entry assembly, /// load from environment variables, @@ -63,10 +64,9 @@ public static class BatchHost /// The initialized . public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel, string hostEnvironmentVariable) { - var builder = new HostBuilder(); + var builder = Host.CreateDefaultBuilder(); ConfigureHostConfigurationDefault(builder, hostEnvironmentVariable); - ConfigureAppConfigurationDefault(builder); ConfigureLoggingDefault(builder, useSimpleConsoleLogger, minSimpleConsoleLoggerLogLevel); return builder; @@ -74,11 +74,12 @@ public static IHostBuilder CreateDefaultBuilder(bool useSimpleConsoleLogger, Log internal static void ConfigureHostConfigurationDefault(IHostBuilder builder, string hostEnvironmentVariable) { - builder.UseContentRoot(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)); - builder.ConfigureHostConfiguration(config => { + // NOTE: This is backward compatibility for v1.3.0 or before. + // It's strongly recommended to use "DOTNET_" prefix expected by GenericHost. (e.g. DOTNET_ENVIRONMENT) config.AddEnvironmentVariables(prefix: "NETCORE_"); + config.AddInMemoryCollection(new[] { new KeyValuePair(HostDefaults.ApplicationKey, Assembly.GetExecutingAssembly().GetName().Name) }); }); @@ -88,35 +89,19 @@ internal static void ConfigureHostConfigurationDefault(IHostBuilder builder, str } } - internal static void ConfigureAppConfigurationDefault(IHostBuilder builder) - { - builder.ConfigureAppConfiguration((hostingContext, config) => - { - var env = hostingContext.HostingEnvironment; - - config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true); - config.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true); - - if (env.IsDevelopment()) - { - var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName)); - if (appAssembly != null) - { - // use https://marketplace.visualstudio.com/items?itemName=guitarrapc.OpenUserSecrets to easily manage UserSecrets with GenericHost. - config.AddUserSecrets(appAssembly, optional: true); - } - } - - config.AddEnvironmentVariables(); - }); - } - internal static void ConfigureLoggingDefault(IHostBuilder builder, bool useSimpleConsoleLogger, LogLevel minSimpleConsoleLoggerLogLevel) { if (useSimpleConsoleLogger) { builder.ConfigureLogging(logging => { + // Use SimpleConsoleLogger instead of the default ConsoleLogger. + var consoleLogger = logging.Services.FirstOrDefault(x => x.ImplementationType?.FullName == "Microsoft.Extensions.Logging.Console.ConsoleLoggerProvider"); + if (consoleLogger != null) + { + logging.Services.Remove(consoleLogger); + } + logging.AddSimpleConsole(); logging.AddFilter((category, level) => { diff --git a/src/MicroBatchFramework/MicroBatchFramework.csproj b/src/MicroBatchFramework/MicroBatchFramework.csproj index 04b811a..b5a7ab5 100644 --- a/src/MicroBatchFramework/MicroBatchFramework.csproj +++ b/src/MicroBatchFramework/MicroBatchFramework.csproj @@ -26,10 +26,7 @@ - - - - + diff --git a/tests/MicroBatchFramework.Tests/MicroBatchFramework.Tests.csproj b/tests/MicroBatchFramework.Tests/MicroBatchFramework.Tests.csproj index f6f1a3c..93b548c 100644 --- a/tests/MicroBatchFramework.Tests/MicroBatchFramework.Tests.csproj +++ b/tests/MicroBatchFramework.Tests/MicroBatchFramework.Tests.csproj @@ -1,7 +1,7 @@  - netcoreapp2.1 + netcoreapp3.0 false @@ -11,7 +11,6 @@ -