diff --git a/EventFlow.sln b/EventFlow.sln index 554a301fc..e12db7294 100644 --- a/EventFlow.sln +++ b/EventFlow.sln @@ -29,6 +29,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.MsSql", "Source\E EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.MsSql.Tests", "Source\EventFlow.MsSql.Tests\EventFlow.MsSql.Tests.csproj", "{CE19355C-6355-405F-A640-908AE4F83C2C}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EventFlow.AspNetCore", "Source\EventFlow.AspNetCore\EventFlow.AspNetCore.csproj", "{4E39F832-B280-465B-823B-FB5470F511CF}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "AspNetCore", "AspNetCore", "{C3E24CD7-CD44-433E-9902-D5C97A5FEA3F}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -71,6 +75,10 @@ Global {CE19355C-6355-405F-A640-908AE4F83C2C}.Debug|Any CPU.Build.0 = Debug|Any CPU {CE19355C-6355-405F-A640-908AE4F83C2C}.Release|Any CPU.ActiveCfg = Release|Any CPU {CE19355C-6355-405F-A640-908AE4F83C2C}.Release|Any CPU.Build.0 = Release|Any CPU + {4E39F832-B280-465B-823B-FB5470F511CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {4E39F832-B280-465B-823B-FB5470F511CF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {4E39F832-B280-465B-823B-FB5470F511CF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {4E39F832-B280-465B-823B-FB5470F511CF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -84,6 +92,7 @@ Global {983EFD08-2256-4361-A869-23EB872328CB} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} {96A39EA3-6772-409E-AF0B-C5A35A1A13CC} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} {CE19355C-6355-405F-A640-908AE4F83C2C} = {88359036-4F35-487C-BF2C-4F31C7BC92D8} + {4E39F832-B280-465B-823B-FB5470F511CF} = {C3E24CD7-CD44-433E-9902-D5C97A5FEA3F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {17607E2C-4E8E-45A2-85BD-0A5808E1C0F3} diff --git a/Source/EventFlow.AspNetCore/Configuration/EventFlowModelBindingMvcConfiguration.cs b/Source/EventFlow.AspNetCore/Configuration/EventFlowModelBindingMvcConfiguration.cs index b790a88b5..89f6c0165 100644 --- a/Source/EventFlow.AspNetCore/Configuration/EventFlowModelBindingMvcConfiguration.cs +++ b/Source/EventFlow.AspNetCore/Configuration/EventFlowModelBindingMvcConfiguration.cs @@ -39,4 +39,4 @@ public void Configure(MvcOptions options) } } } -} \ No newline at end of file +} diff --git a/Source/EventFlow.AspNetCore/EventFlow.AspNetCore.csproj b/Source/EventFlow.AspNetCore/EventFlow.AspNetCore.csproj index c390e83be..0ec3b1d33 100644 --- a/Source/EventFlow.AspNetCore/EventFlow.AspNetCore.csproj +++ b/Source/EventFlow.AspNetCore/EventFlow.AspNetCore.csproj @@ -22,21 +22,27 @@ - - - - + + + + + + + - + + + + diff --git a/Source/EventFlow.AspNetCore/Extensions/AspNetCoreEventFlowOptions.cs b/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsAspNetCoreExtensions.cs similarity index 59% rename from Source/EventFlow.AspNetCore/Extensions/AspNetCoreEventFlowOptions.cs rename to Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsAspNetCoreExtensions.cs index abd928937..62a497d66 100644 --- a/Source/EventFlow.AspNetCore/Extensions/AspNetCoreEventFlowOptions.cs +++ b/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsAspNetCoreExtensions.cs @@ -23,68 +23,53 @@ using System; using EventFlow.AspNetCore.Configuration; -using EventFlow.AspNetCore.Logging; using EventFlow.AspNetCore.MetadataProviders; -using EventFlow.AspNetCore.ServiceProvider; using EventFlow.EventStores; using EventFlow.Extensions; -using EventFlow.Logs; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; namespace EventFlow.AspNetCore.Extensions { - public class AspNetCoreEventFlowOptions + public class EventFlowOptionsAspNetCoreExtensions { private readonly IEventFlowOptions _options; - public AspNetCoreEventFlowOptions(IEventFlowOptions options) + public EventFlowOptionsAspNetCoreExtensions(IEventFlowOptions options) { _options = options; } - public AspNetCoreEventFlowOptions AddUriMetadata() + public EventFlowOptionsAspNetCoreExtensions AddUriMetadata() { return RegisterMetadataProvider(); } - public AspNetCoreEventFlowOptions AddRequestHeadersMetadata() + public EventFlowOptionsAspNetCoreExtensions AddRequestHeadersMetadata() { return RegisterMetadataProvider(); } - public AspNetCoreEventFlowOptions AddUserHostAddressMetadata() + public EventFlowOptionsAspNetCoreExtensions AddUserHostAddressMetadata() { return RegisterMetadataProvider(); } - public AspNetCoreEventFlowOptions AddUserClaimsMetadata(params string[] includedClaimTypes) + public EventFlowOptionsAspNetCoreExtensions AddUserClaimsMetadata(params string[] includedClaimTypes) { var options = new DefaultUserClaimsMetadataOptions(includedClaimTypes); - _options.RegisterServices(s => s.Register(_ => options)); + _options.RegisterServices(s => s.AddTransient(_ => options)); return RegisterMetadataProvider(); } - public AspNetCoreEventFlowOptions UseLogging() + public EventFlowOptionsAspNetCoreExtensions UseDefaults() { - _options.RegisterServices(s => s.Register()); - return this; - } - - public AspNetCoreEventFlowOptions UseDefaults() - { - return RunBootstrapperOnHostStartup().AddDefaultMetadataProviders(); - } - - public AspNetCoreEventFlowOptions RunBootstrapperOnHostStartup() - { - _options.RegisterServices(s => s.Register(Lifetime.Singleton)); - return this; + return AddDefaultMetadataProviders(); } - public AspNetCoreEventFlowOptions AddDefaultMetadataProviders() + public EventFlowOptionsAspNetCoreExtensions AddDefaultMetadataProviders() { AddRequestHeadersMetadata(); AddUriMetadata(); @@ -93,37 +78,36 @@ public AspNetCoreEventFlowOptions AddDefaultMetadataProviders() } #if NETSTANDARD2_0 - public AspNetCoreEventFlowOptions UseMvcJsonOptions() + public EventFlowOptionsAspNetCoreExtensions UseMvcJsonOptions() { _options.RegisterServices(s => - s.Register, EventFlowJsonOptionsMvcConfiguration>()); + s.AddTransient, EventFlowJsonOptionsMvcConfiguration>()); return this; } #endif #if (NETCOREAPP3_0 || NETCOREAPP3_1) - public AspNetCoreEventFlowOptions UseMvcJsonOptions() + public EventFlowOptionsAspNetCoreExtensions UseMvcJsonOptions() { _options.RegisterServices(s => - s.Register, EventFlowJsonOptionsMvcConfiguration>()); + s.AddTransient, EventFlowJsonOptionsMvcConfiguration>()); return this; } #endif - public AspNetCoreEventFlowOptions UseModelBinding( + public EventFlowOptionsAspNetCoreExtensions UseModelBinding( Action configureModelBinding = null) { var modelBindingOptions = new EventFlowModelBindingMvcConfiguration(); configureModelBinding?.Invoke(modelBindingOptions); - _options.RegisterServices(s => s.Register>(c => modelBindingOptions)); + _options.RegisterServices(s => s.AddTransient>(c => modelBindingOptions)); return this; } - private AspNetCoreEventFlowOptions RegisterMetadataProvider() where T : class, IMetadataProvider + private EventFlowOptionsAspNetCoreExtensions RegisterMetadataProvider() where T : class, IMetadataProvider { _options .AddMetadataProvider() - .RegisterServices(s => - s.Register(Lifetime.Singleton, true)); + .RegisterServices(s => s.AddSingleton()); return this; } diff --git a/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsExtensions.cs b/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsExtensions.cs index a932054ed..7f2cffe8a 100644 --- a/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsExtensions.cs +++ b/Source/EventFlow.AspNetCore/Extensions/EventFlowOptionsExtensions.cs @@ -29,21 +29,17 @@ public static class EventFlowOptionsExtensions { public static IEventFlowOptions AddAspNetCore( this IEventFlowOptions options, - Action configuratioAction = null) + Action configurationAction = null) { - var aspNetCoreOptions = new AspNetCoreEventFlowOptions(options); - if (configuratioAction == null) configuratioAction = o => o.UseDefaults(); + var aspNetCoreOptions = new EventFlowOptionsAspNetCoreExtensions(options); + if (configurationAction == null) + { + configurationAction = o => o.UseDefaults(); + } - configuratioAction(aspNetCoreOptions); + configurationAction(aspNetCoreOptions); return options; } - - [Obsolete("Use AddAspNetCore(o => o...)")] - public static IEventFlowOptions AddAspNetCoreMetadataProviders( - this IEventFlowOptions eventFlowOptions) - { - return eventFlowOptions.AddAspNetCore(); - } } } diff --git a/Source/EventFlow.AspNetCore/Logging/AspNetCoreLoggerLog.cs b/Source/EventFlow.AspNetCore/Logging/AspNetCoreLoggerLog.cs deleted file mode 100644 index 266394af8..000000000 --- a/Source/EventFlow.AspNetCore/Logging/AspNetCoreLoggerLog.cs +++ /dev/null @@ -1,56 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2015-2021 Rasmus Mikkelsen -// Copyright (c) 2015-2021 eBay Software Foundation -// https://github.com/eventflow/EventFlow -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -using System; -using EventFlow.Logs; -using Microsoft.Extensions.Logging; -using LogLevel = Microsoft.Extensions.Logging.LogLevel; - -namespace EventFlow.AspNetCore.Logging -{ - public class AspNetCoreLoggerLog : Log - { - private readonly ILogger _logger; - - public AspNetCoreLoggerLog(ILogger logger) - { - _logger = logger; - } - - protected override bool IsVerboseEnabled => _logger.IsEnabled(LogLevel.Trace); - - protected override bool IsInformationEnabled => _logger.IsEnabled(LogLevel.Information); - - protected override bool IsDebugEnabled => _logger.IsEnabled(LogLevel.Debug); - - public override void Write(Logs.LogLevel logLevel, string format, params object[] args) - { - _logger.Log((LogLevel)logLevel, format, args); - } - - public override void Write(Logs.LogLevel logLevel, Exception exception, string format, params object[] args) - { - _logger.Log((LogLevel)logLevel, exception, format, args); - } - } -} diff --git a/Source/EventFlow.AspNetCore/MetadataProviders/AddRequestHeadersMetadataProvider.cs b/Source/EventFlow.AspNetCore/MetadataProviders/AddRequestHeadersMetadataProvider.cs index c76bcadaf..d67ac5b77 100644 --- a/Source/EventFlow.AspNetCore/MetadataProviders/AddRequestHeadersMetadataProvider.cs +++ b/Source/EventFlow.AspNetCore/MetadataProviders/AddRequestHeadersMetadataProvider.cs @@ -33,11 +33,11 @@ namespace EventFlow.AspNetCore.MetadataProviders { public class AddRequestHeadersMetadataProvider : IMetadataProvider { - private static readonly ISet RequestHeadersToSkip = new HashSet - { - "Authorization", - "Cookie" - }; + private static readonly ISet RequestHeadersToSkip = new HashSet(StringComparer.OrdinalIgnoreCase) + { + "Authorization", + "Cookie" + }; private readonly IHttpContextAccessor _httpContextAccessor; diff --git a/Source/EventFlow.AspNetCore/MetadataProviders/AddUriMetadataProvider.cs b/Source/EventFlow.AspNetCore/MetadataProviders/AddUriMetadataProvider.cs index e87e8beb9..2ce0dfe63 100644 --- a/Source/EventFlow.AspNetCore/MetadataProviders/AddUriMetadataProvider.cs +++ b/Source/EventFlow.AspNetCore/MetadataProviders/AddUriMetadataProvider.cs @@ -47,10 +47,13 @@ public IEnumerable> ProvideMetadata("request_uri", request.Path.ToString()); yield return new KeyValuePair("request_proto", request.Protocol.ToUpperInvariant()); yield return new KeyValuePair("request_method", request.Method.ToUpperInvariant()); diff --git a/Source/EventFlow.AspNetCore/MetadataProviders/AddUserClaimsMetadataProvider.cs b/Source/EventFlow.AspNetCore/MetadataProviders/AddUserClaimsMetadataProvider.cs index 75aaa3187..3c1953304 100644 --- a/Source/EventFlow.AspNetCore/MetadataProviders/AddUserClaimsMetadataProvider.cs +++ b/Source/EventFlow.AspNetCore/MetadataProviders/AddUserClaimsMetadataProvider.cs @@ -51,7 +51,8 @@ public IEnumerable> ProvideMetadata>(); - return from claim in user.Claims + return + from claim in user.Claims where _options.IsIncluded(claim.Type) group claim by claim.Type into claimGroup diff --git a/Source/EventFlow.AspNetCore/MetadataProviders/AddUserHostAddressMetadataProvider.cs b/Source/EventFlow.AspNetCore/MetadataProviders/AddUserHostAddressMetadataProvider.cs index ffe56f1ed..1daa4e374 100644 --- a/Source/EventFlow.AspNetCore/MetadataProviders/AddUserHostAddressMetadataProvider.cs +++ b/Source/EventFlow.AspNetCore/MetadataProviders/AddUserHostAddressMetadataProvider.cs @@ -27,7 +27,6 @@ using EventFlow.Core; using EventFlow.EventStores; using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.Primitives; namespace EventFlow.AspNetCore.MetadataProviders { @@ -58,7 +57,9 @@ public IEnumerable> ProvideMetadata("remote_ip_address", httpContext.Connection.RemoteIpAddress?.ToString()); diff --git a/Source/EventFlow.AspNetCore/Middlewares/CommandPublishMiddleware.cs b/Source/EventFlow.AspNetCore/Middlewares/CommandPublishMiddleware.cs index d5f09735d..5eb04f25b 100644 --- a/Source/EventFlow.AspNetCore/Middlewares/CommandPublishMiddleware.cs +++ b/Source/EventFlow.AspNetCore/Middlewares/CommandPublishMiddleware.cs @@ -30,8 +30,8 @@ using EventFlow.Commands; using EventFlow.Core; using EventFlow.Exceptions; -using EventFlow.Logs; using Microsoft.AspNetCore.Http; +using Microsoft.Extensions.Logging; namespace EventFlow.AspNetCore.Middlewares { @@ -42,18 +42,18 @@ public class CommandPublishMiddleware RegexOptions.Compiled | RegexOptions.IgnoreCase); private readonly RequestDelegate _next; - private readonly ILog _log; + private readonly ILogger _logger; private readonly IJsonSerializer _jsonSerializer; private readonly ISerializedCommandPublisher _serializedCommandPublisher; public CommandPublishMiddleware( RequestDelegate next, - ILog log, + ILogger logger, IJsonSerializer jsonSerializer, ISerializedCommandPublisher serializedCommandPublisher) { _next = next; - _log = log; + _logger = logger; _jsonSerializer = jsonSerializer; _serializedCommandPublisher = serializedCommandPublisher; } @@ -80,7 +80,10 @@ await PublishCommandAsync( private async Task PublishCommandAsync(string name, int version, HttpContext context) { - _log.Verbose($"Publishing command '{name}' v{version} from OWIN middleware"); + _logger.LogTrace( + "Publishing command {CommandName} version {CommandVersion} from ASP.NET Core middleware", + name, + version); string requestJson; using (var streamReader = new StreamReader(context.Request.Body)) @@ -90,12 +93,13 @@ private async Task PublishCommandAsync(string name, int version, HttpContext con try { - var sourceId = await _serializedCommandPublisher.PublishSerilizedCommandAsync( + var sourceId = await _serializedCommandPublisher.PublishSerializedCommandAsync( name, version, requestJson, - CancellationToken.None) + CancellationToken.None) /* TODO: Determine if we should use context.RequestAborted */ .ConfigureAwait(false); + await WriteAsync( new { @@ -107,7 +111,13 @@ await WriteAsync( } catch (ArgumentException e) { - _log.Debug(e, $"Failed to publish serialized command '{name}' v{version} due to: {e.Message}"); + _logger.LogDebug( + e, + "Failed to publish serialized command {CommandName} version {CommandVersion} due to: {ExceptionMessage}", + name, + version, + e.Message); + await WriteErrorAsync(e.Message, HttpStatusCode.BadRequest, context).ConfigureAwait(false); } catch (DomainError e) @@ -116,7 +126,11 @@ await WriteAsync( } catch (Exception e) { - _log.Error(e, $"Unexpected exception when executing '{name}' v{version}"); + _logger.LogError( + e, "Unexpected exception when executing {CommandName} version {CommandVersion}", + name, + version); + await WriteErrorAsync("Internal server error!", HttpStatusCode.InternalServerError, context).ConfigureAwait(false); } } @@ -139,4 +153,4 @@ private Task WriteErrorAsync(string errorMessage, HttpStatusCode statusCode, Htt context); } } -} \ No newline at end of file +} diff --git a/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinder.cs b/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinder.cs index 7cee93cc7..c93f0684c 100644 --- a/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinder.cs +++ b/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinder.cs @@ -24,7 +24,6 @@ using System; using System.ComponentModel; using System.Linq; -using System.Reflection; using System.Runtime.ExceptionServices; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -35,13 +34,13 @@ internal class SingleValueModelBinder : IModelBinder { public Task BindModelAsync(ModelBindingContext bindingContext) { - Type modelType = bindingContext.ModelType; - ConstructorInfo constructor = modelType.GetConstructors().Single(); - Type parameterType = constructor.GetParameters().Single().ParameterType; + var modelType = bindingContext.ModelType; + var constructor = modelType.GetConstructors().Single(); + var parameterType = constructor.GetParameters().Single().ParameterType; var modelName = bindingContext.ModelName; - ValueProviderResult valueProviderResult = bindingContext.ValueProvider.GetValue(modelName); + var valueProviderResult = bindingContext.ValueProvider.GetValue(modelName); if (valueProviderResult == ValueProviderResult.None) { return Task.CompletedTask; @@ -60,7 +59,7 @@ public Task BindModelAsync(ModelBindingContext bindingContext) } else { - TypeConverter converter = TypeDescriptor.GetConverter(parameterType); + var converter = TypeDescriptor.GetConverter(parameterType); if (!converter.CanConvertFrom(typeof(string))) { return Task.CompletedTask; @@ -74,9 +73,15 @@ public Task BindModelAsync(ModelBindingContext bindingContext) catch (Exception e) { if (!(e is FormatException) && e.InnerException != null) + { e = ExceptionDispatchInfo.Capture(e.InnerException).SourceException; - bindingContext.ModelState.TryAddModelError(bindingContext.ModelName, e, + } + + bindingContext.ModelState.TryAddModelError( + bindingContext.ModelName, + e, bindingContext.ModelMetadata); + return Task.CompletedTask; } @@ -86,4 +91,4 @@ public Task BindModelAsync(ModelBindingContext bindingContext) return Task.CompletedTask; } } -} \ No newline at end of file +} diff --git a/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinderProvider.cs b/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinderProvider.cs index 72955b090..60c255dd1 100644 --- a/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinderProvider.cs +++ b/Source/EventFlow.AspNetCore/ModelBinding/SingleValueModelBinderProvider.cs @@ -21,7 +21,6 @@ // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -using System; using EventFlow.ValueObjects; using Microsoft.AspNetCore.Mvc.ModelBinding; @@ -31,11 +30,11 @@ internal class SingleValueModelBinderProvider : IModelBinderProvider { public IModelBinder GetBinder(ModelBinderProviderContext context) { - Type modelType = context.Metadata.ModelType; + var modelType = context.Metadata.ModelType; return typeof(ISingleValueObject).IsAssignableFrom(modelType) ? new SingleValueModelBinder() : null; } } -} \ No newline at end of file +} diff --git a/Source/EventFlow.AspNetCore/ServiceProvider/HostedBootstrapper.cs b/Source/EventFlow.AspNetCore/ServiceProvider/HostedBootstrapper.cs deleted file mode 100644 index 6500f6ce3..000000000 --- a/Source/EventFlow.AspNetCore/ServiceProvider/HostedBootstrapper.cs +++ /dev/null @@ -1,56 +0,0 @@ -// The MIT License (MIT) -// -// Copyright (c) 2015-2021 Rasmus Mikkelsen -// Copyright (c) 2015-2021 eBay Software Foundation -// https://github.com/eventflow/EventFlow -// -// Permission is hereby granted, free of charge, to any person obtaining a copy of -// this software and associated documentation files (the "Software"), to deal in -// the Software without restriction, including without limitation the rights to -// use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -// the Software, and to permit persons to whom the Software is furnished to do so, -// subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in all -// copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - -using System.Threading; -using System.Threading.Tasks; -using EventFlow.Configuration.Bootstraps; -using Microsoft.Extensions.Hosting; - -namespace EventFlow.AspNetCore.ServiceProvider -{ - /// - /// Ensures that the is run in an ASP.NET Core - /// environment when EventFlow is configured into an existing ServiceCollection - /// instance and is not used. - /// - // ReSharper disable once ClassNeverInstantiated.Local - class HostedBootstrapper : IHostedService - { - private readonly IBootstrapper _bootstrapper; - - public HostedBootstrapper(IBootstrapper bootstrapper) - { - _bootstrapper = bootstrapper; - } - - public Task StartAsync(CancellationToken cancellationToken) - { - return _bootstrapper.StartAsync(cancellationToken); - } - - public Task StopAsync(CancellationToken cancellationToken) - { - return Task.CompletedTask; - } - } -}