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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Options;

using NetCord.Hosting.Gateway;
Expand Down Expand Up @@ -192,6 +193,8 @@ public static IServiceCollection AddHttpApplicationCommands(
services.AddShardedGatewayHandler(services => services.GetRequiredService<ApplicationCommandInteractionHandler<TInteraction, TContext>>());
services.AddHttpInteractionHandler(services => services.GetRequiredService<ApplicationCommandInteractionHandler<TInteraction, TContext>>());

services.TryAddTransient(CreateServiceManager);

services.AddHostedService<ApplicationCommandServiceHostedService>();

return services;
Expand Down Expand Up @@ -277,8 +280,23 @@ public static IServiceCollection AddHttpApplicationCommands(
services.AddShardedGatewayHandler(services => services.GetRequiredService<AutocompleteInteractionHandler<TInteraction, TContext, TAutocompleteContext>>());
services.AddHttpInteractionHandler(services => services.GetRequiredService<AutocompleteInteractionHandler<TInteraction, TContext, TAutocompleteContext>>());

services.TryAddTransient(CreateServiceManager);

services.AddHostedService<ApplicationCommandServiceHostedService>();

return services;
}

private static ApplicationCommandServiceManager CreateServiceManager(IServiceProvider services)
{
List<IApplicationCommandService> managerServices = [];

foreach (var serviceData in services.GetServices<ApplicationCommandServiceData>())
{
serviceData.Builder.Build();
managerServices.Add(serviceData.Service);
}

return new(managerServices);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public EntryPointCommandBuilder AddEntryPointCommand(string name, string descrip

public void Build()
{
var builders = _builders;
var builders = Interlocked.Exchange(ref _builders, []);
int count = builders.Count;

for (int i = 0; i < count; i++)
Expand All @@ -100,8 +100,6 @@ public void Build()
break;
}
}

_builders = [];
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CommandGroupBuilder AddCommandGroup(IEnumerable<string> aliases, Action<C

public void Build()
{
var (builders, groupBuilders) = _data;
var (builders, groupBuilders) = Interlocked.Exchange(ref _data, new());

int buildersCount = builders.Count;

Expand All @@ -61,7 +61,5 @@ public void Build()

for (int i = 0; i < groupBuildersCount; i++)
service.AddCommandGroup(groupBuilders[i]);

_data = new();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ public ComponentInteractionBuilder AddComponentInteraction(string customId, Dele

public void Build()
{
var builders = _builders;
var builders = Interlocked.Exchange(ref _builders, []);
int count = builders.Count;

for (int i = 0; i < count; i++)
service.AddComponentInteraction(builders[i]);

_builders = [];
}
}
Loading