Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<PackageIcon>icon.jpg</PackageIcon>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>9.0.2</Version>
<DotNetVersion>[10.0.0,11.0.0)</DotNetVersion>
<LangVersion>latest</LangVersion>
</PropertyGroup>

Expand Down
38 changes: 38 additions & 0 deletions src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Microsoft.AspNetCore.Builder;
using TickerQ.Utilities.Enums;
using System;
using Microsoft.Extensions.DependencyInjection;
using TickerQ.DependencyInjection;

Check failure on line 5 in src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The type or namespace name 'DependencyInjection' does not exist in the namespace 'TickerQ' (are you missing an assembly reference?)

Check failure on line 5 in src/TickerQ.Dashboard/DependencyInjection/AspNetCoreExtensions.cs

View workflow job for this annotation

GitHub Actions / PR Build and Test

The type or namespace name 'DependencyInjection' does not exist in the namespace 'TickerQ' (are you missing an assembly reference?)
using TickerQ.Utilities;

namespace TickerQ.Dashboard.DependencyInjection
{
/// <summary>
/// ASP.NET Core specific extensions for TickerQ with Dashboard support
/// </summary>
public static class AspNetCoreExtensions
{
/// <summary>
/// Initializes TickerQ for ASP.NET Core applications with Dashboard support
/// </summary>
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<TickerExecutionContext>();
if (tickerExecutionContext?.DashboardApplicationAction != null)
{
// Cast object back to IApplicationBuilder for Dashboard middleware
tickerExecutionContext.DashboardApplicationAction(app);
tickerExecutionContext.DashboardApplicationAction = null;
}

return app;
}
}
}

4 changes: 2 additions & 2 deletions src/TickerQ.Utilities/TickerExecutionContext.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -18,7 +18,7 @@ internal class TickerExecutionContext
{
private long _nextOccurrenceTicks;
internal Action<IServiceProvider> ExternalProviderApplicationAction { get; set; }
internal Action<IApplicationBuilder> DashboardApplicationAction { get; set; }
internal Action<object> DashboardApplicationAction { get; set; }
public Action<object, CoreNotifyActionType> NotifyCoreAction { get; set; }
public string LastHostExceptionMessage { get; set; }
internal ITickerOptionsSeeding OptionsSeeding { get; set; }
Expand Down
4 changes: 2 additions & 2 deletions src/TickerQ.Utilities/TickerOptionsBuilder.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -171,7 +171,7 @@ public TickerOptionsBuilder<TTimeTicker, TCronTicker> SetExceptionHandler<THandl
internal void UseExternalProviderApplication(Action<IServiceProvider> action)
=> _tickerExecutionContext.ExternalProviderApplicationAction = action;

internal void UseDashboardApplication(Action<IApplicationBuilder> action)
internal void UseDashboardApplication(Action<object> action)
=> _tickerExecutionContext.DashboardApplicationAction = action;
}

Expand Down
32 changes: 22 additions & 10 deletions src/TickerQ/DependencyInjection/TickerQServiceExtensions.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -90,9 +90,26 @@ public static IServiceCollection AddTickerQ<TTimeTicker, TCronTicker>(this IServ
return services;
}

public static IApplicationBuilder UseTickerQ(this IApplicationBuilder app, TickerQStartMode qStartMode = TickerQStartMode.Immediate)
/// <summary>
/// Initializes TickerQ for generic host applications (Console, MAUI, WPF, Worker Services, etc.)
/// </summary>
public static IHost UseTickerQ(this IHost host, TickerQStartMode qStartMode = TickerQStartMode.Immediate)
{
InitializeTickerQ(host.Services, qStartMode);
return host;
}

/// <summary>
/// Initializes TickerQ with a service provider directly
/// </summary>
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<TickerExecutionContext>();
var configuration = serviceProvider.GetService<IConfiguration>();
var notificationHubSender = serviceProvider.GetService<ITickerQNotificationHubSender>();
Expand Down Expand Up @@ -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)
Expand Down
Loading