diff --git a/src/Directory.Build.props b/src/Directory.Build.props index ab988da5..7cf26501 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -9,6 +9,7 @@ icon.jpg true 10.0.2 + [10.0.0,11.0.0) latest diff --git a/src/TickerQ.Caching.StackExchangeRedis/TickerQ.Caching.StackExchangeRedis.csproj b/src/TickerQ.Caching.StackExchangeRedis/TickerQ.Caching.StackExchangeRedis.csproj index 957c1729..749cc711 100644 --- a/src/TickerQ.Caching.StackExchangeRedis/TickerQ.Caching.StackExchangeRedis.csproj +++ b/src/TickerQ.Caching.StackExchangeRedis/TickerQ.Caching.StackExchangeRedis.csproj @@ -1,4 +1,4 @@ - + enable @@ -9,10 +9,7 @@ - - - - + diff --git a/src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs b/src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs new file mode 100644 index 00000000..b8df940f --- /dev/null +++ b/src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs @@ -0,0 +1,38 @@ +using Microsoft.AspNetCore.Builder; +using TickerQ.Utilities.Enums; +using System; +using Microsoft.Extensions.DependencyInjection; +using TickerQ.DependencyInjection; +using TickerQ.Utilities; + +namespace TickerQ.Dashboard.DependencyInjection +{ + /// + /// ASP.NET Core specific extensions for TickerQ with Dashboard support + /// + public static class AspNetCoreExtensions + { + /// + /// Initializes TickerQ for ASP.NET Core applications with Dashboard support + /// + public static IApplicationBuilder UseTickerQ(this IApplicationBuilder app, TickerQStartMode qStartMode = TickerQStartMode.Immediate) + { + var serviceProvider = app.ApplicationServices; + + // Initialize core TickerQ functionality using the base extension from TickerQ package + serviceProvider.UseTickerQ(qStartMode); + + // Handle Dashboard-specific initialization if configured + var tickerExecutionContext = serviceProvider.GetService(); + if (tickerExecutionContext?.DashboardApplicationAction != null) + { + // Cast object back to IApplicationBuilder for Dashboard middleware + tickerExecutionContext.DashboardApplicationAction(app); + tickerExecutionContext.DashboardApplicationAction = null; + } + + return app; + } + } +} + diff --git a/src/TickerQ.EntityFrameworkCore/TickerQ.EntityFrameworkCore.csproj b/src/TickerQ.EntityFrameworkCore/TickerQ.EntityFrameworkCore.csproj index 40ba58b5..9bbfb73c 100644 --- a/src/TickerQ.EntityFrameworkCore/TickerQ.EntityFrameworkCore.csproj +++ b/src/TickerQ.EntityFrameworkCore/TickerQ.EntityFrameworkCore.csproj @@ -13,7 +13,7 @@ - + diff --git a/src/TickerQ.Instrumentation.OpenTelemetry/TickerQ.Instrumentation.OpenTelemetry.csproj b/src/TickerQ.Instrumentation.OpenTelemetry/TickerQ.Instrumentation.OpenTelemetry.csproj index 51c1ed7c..226f76ae 100644 --- a/src/TickerQ.Instrumentation.OpenTelemetry/TickerQ.Instrumentation.OpenTelemetry.csproj +++ b/src/TickerQ.Instrumentation.OpenTelemetry/TickerQ.Instrumentation.OpenTelemetry.csproj @@ -11,8 +11,8 @@ - - + + diff --git a/src/TickerQ.Utilities/TickerExecutionContext.cs b/src/TickerQ.Utilities/TickerExecutionContext.cs index 18be64ae..21508c9d 100644 --- a/src/TickerQ.Utilities/TickerExecutionContext.cs +++ b/src/TickerQ.Utilities/TickerExecutionContext.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.InteropServices; using System.Threading; -using Microsoft.AspNetCore.Builder; +using Microsoft.Extensions.Hosting; using TickerQ.Utilities.Enums; using TickerQ.Utilities.Models; @@ -18,7 +18,7 @@ internal class TickerExecutionContext { private long _nextOccurrenceTicks; internal Action ExternalProviderApplicationAction { get; set; } - internal Action DashboardApplicationAction { get; set; } + internal Action DashboardApplicationAction { get; set; } public Action NotifyCoreAction { get; set; } public string LastHostExceptionMessage { get; set; } internal ITickerOptionsSeeding OptionsSeeding { get; set; } diff --git a/src/TickerQ.Utilities/TickerOptionsBuilder.cs b/src/TickerQ.Utilities/TickerOptionsBuilder.cs index bf51fe32..8383d697 100644 --- a/src/TickerQ.Utilities/TickerOptionsBuilder.cs +++ b/src/TickerQ.Utilities/TickerOptionsBuilder.cs @@ -1,7 +1,7 @@ using System; using System.Text.Json; -using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using TickerQ.Utilities.Entities; using TickerQ.Utilities.Interfaces; using TickerQ.Utilities.Interfaces.Managers; @@ -171,7 +171,7 @@ public TickerOptionsBuilder SetExceptionHandler action) => _tickerExecutionContext.ExternalProviderApplicationAction = action; - internal void UseDashboardApplication(Action action) + internal void UseDashboardApplication(Action action) => _tickerExecutionContext.DashboardApplicationAction = action; } diff --git a/src/TickerQ.Utilities/TickerQ.Utilities.csproj b/src/TickerQ.Utilities/TickerQ.Utilities.csproj index 9c42a379..464a3bd8 100644 --- a/src/TickerQ.Utilities/TickerQ.Utilities.csproj +++ b/src/TickerQ.Utilities/TickerQ.Utilities.csproj @@ -12,11 +12,12 @@ - - - - - + + + + + + \ No newline at end of file diff --git a/src/TickerQ/DependencyInjection/TickerQServiceExtensions.cs b/src/TickerQ/DependencyInjection/TickerQServiceExtensions.cs index 916c5fd7..ca5b63f0 100644 --- a/src/TickerQ/DependencyInjection/TickerQServiceExtensions.cs +++ b/src/TickerQ/DependencyInjection/TickerQServiceExtensions.cs @@ -1,9 +1,9 @@ using System; using System.Linq; using System.Threading.Tasks; -using Microsoft.AspNetCore.Builder; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using TickerQ.BackgroundServices; using TickerQ.Dispatcher; using TickerQ.Provider; @@ -90,9 +90,26 @@ public static IServiceCollection AddTickerQ(this IServ return services; } - public static IApplicationBuilder UseTickerQ(this IApplicationBuilder app, TickerQStartMode qStartMode = TickerQStartMode.Immediate) + /// + /// Initializes TickerQ for generic host applications (Console, MAUI, WPF, Worker Services, etc.) + /// + public static IHost UseTickerQ(this IHost host, TickerQStartMode qStartMode = TickerQStartMode.Immediate) + { + InitializeTickerQ(host.Services, qStartMode); + return host; + } + + /// + /// Initializes TickerQ with a service provider directly + /// + public static IServiceProvider UseTickerQ(this IServiceProvider serviceProvider, TickerQStartMode qStartMode = TickerQStartMode.Immediate) + { + InitializeTickerQ(serviceProvider, qStartMode); + return serviceProvider; + } + + private static void InitializeTickerQ(IServiceProvider serviceProvider, TickerQStartMode qStartMode) { - var serviceProvider = app.ApplicationServices; var tickerExecutionContext = serviceProvider.GetService(); var configuration = serviceProvider.GetService(); var notificationHubSender = serviceProvider.GetService(); @@ -149,13 +166,8 @@ public static IApplicationBuilder UseTickerQ(this IApplicationBuilder app, Ticke tickerExecutionContext.ExternalProviderApplicationAction = null; } - if (tickerExecutionContext?.DashboardApplicationAction != null) - { - tickerExecutionContext.DashboardApplicationAction(app); - tickerExecutionContext.DashboardApplicationAction = null; - } - - return app; + // Dashboard integration is handled by TickerQ.Dashboard package via DashboardApplicationAction + // It will be invoked when UseTickerQ is called from ASP.NET Core specific extension } private static async Task SeedDefinedCronTickers(IServiceProvider serviceProvider) diff --git a/src/TickerQ/TickerQ.csproj b/src/TickerQ/TickerQ.csproj index f6eee539..91d92949 100644 --- a/src/TickerQ/TickerQ.csproj +++ b/src/TickerQ/TickerQ.csproj @@ -14,6 +14,7 @@ + diff --git a/tests/TickerQ.Tests/TickerQ.Tests.csproj b/tests/TickerQ.Tests/TickerQ.Tests.csproj index 96df7e2d..2067b9d5 100644 --- a/tests/TickerQ.Tests/TickerQ.Tests.csproj +++ b/tests/TickerQ.Tests/TickerQ.Tests.csproj @@ -10,6 +10,7 @@ +