@@ -34,38 +34,42 @@ public static class ServiceCollectionExtensions
34
34
/// Adds and optionally configures a <see cref="DiscordShardedClient"/> along with the required services.
35
35
/// </summary>
36
36
/// <remarks>
37
- /// A <see cref="IServiceProvider"/> is supplied so you can pull data from additional services if required.
37
+ /// A <see cref="IServiceProvider"/> is supplied, so you can pull data from additional services if required.
38
38
/// </remarks>
39
39
/// <param name="collection">The service collection to configure.</param>
40
40
/// <param name="config">The delegate for the <see cref="DiscordHostConfiguration" /> that will be used to configure the host.</param>
41
41
/// <exception cref="InvalidOperationException">Thrown if client is already added to the service collection</exception>
42
- public static void AddDiscordShardedHost ( this IServiceCollection collection , Action < DiscordHostConfiguration , IServiceProvider > config )
42
+ public static IServiceCollection AddDiscordShardedHost ( this IServiceCollection collection , Action < DiscordHostConfiguration , IServiceProvider > config )
43
43
{
44
44
collection . AddDiscordHostInternal < DiscordShardedClient > ( config ) ;
45
45
46
46
if ( collection . Any ( x => x . ServiceType . BaseType == typeof ( BaseSocketClient ) ) )
47
47
throw new InvalidOperationException ( "Cannot add more than one Discord Client to host" ) ;
48
48
49
49
collection . AddSingleton < DiscordShardedClient , InjectableDiscordShardedClient > ( ) ;
50
+
51
+ return collection ;
50
52
}
51
53
52
54
/// <summary>
53
55
/// Adds and optionally configures a <see cref="DiscordSocketClient"/> along with the required services.
54
56
/// </summary>
55
57
/// <remarks>
56
- /// A <see cref="IServiceProvider"/> is supplied so you can pull data from additional services if required.
58
+ /// A <see cref="IServiceProvider"/> is supplied, so you can pull data from additional services if required.
57
59
/// </remarks>
58
60
/// <param name="builder">The host builder to configure.</param>
59
61
/// <param name="config">The delegate for the <see cref="DiscordHostConfiguration" /> that will be used to configure the host.</param>
60
62
/// <exception cref="InvalidOperationException">Thrown if client is already added to the service collection</exception>
61
- public static void AddDiscordHost ( this IServiceCollection builder , Action < DiscordHostConfiguration , IServiceProvider > config )
63
+ public static IServiceCollection AddDiscordHost ( this IServiceCollection builder , Action < DiscordHostConfiguration , IServiceProvider > config )
62
64
{
63
65
builder . AddDiscordHostInternal < DiscordSocketClient > ( config ) ;
64
66
65
67
if ( builder . Any ( x => x . ServiceType . BaseType == typeof ( BaseSocketClient ) ) )
66
68
throw new InvalidOperationException ( "Cannot add more than one Discord Client to host" ) ;
67
69
68
70
builder . AddSingleton < DiscordSocketClient , InjectableDiscordSocketClient > ( ) ;
71
+
72
+ return builder ;
69
73
}
70
74
71
75
private static void AddDiscordHostInternal < T > ( this IServiceCollection collection , Action < DiscordHostConfiguration , IServiceProvider > config ) where T : BaseSocketClient
@@ -96,19 +100,19 @@ static bool ValidateToken(string token)
96
100
/// </summary>
97
101
/// <param name="collection">The service collection to configure.</param>
98
102
/// <exception cref="InvalidOperationException">Thrown if <see cref="CommandService"/> is already added to the collection</exception>
99
- public static void AddCommandService ( this IServiceCollection collection ) => collection . AddCommandService ( ( context , config ) => { } ) ;
103
+ public static IServiceCollection AddCommandService ( this IServiceCollection collection ) => collection . AddCommandService ( ( context , config ) => { } ) ;
100
104
101
105
/// <summary>
102
106
/// Adds a <see cref="CommandService"/> instance to the host for use with a Discord.NET client. />
103
107
/// </summary>
104
108
/// <remarks>
105
- /// A <see cref="IServiceProvider"/> is supplied so you can pull data from additional services if required.
109
+ /// A <see cref="IServiceProvider"/> is supplied, so you can pull data from additional services if required.
106
110
/// </remarks>
107
111
/// <param name="collection">The service collection to configure.</param>
108
112
/// <param name="config">The delegate for configuring the <see cref="CommandServiceConfig" /> that will be used to initialise the service.</param>
109
113
/// <exception cref="ArgumentNullException">Thrown if config is null</exception>
110
114
/// <exception cref="InvalidOperationException">Thrown if <see cref="CommandService"/> is already added to the collection</exception>
111
- public static void AddCommandService ( this IServiceCollection collection , Action < CommandServiceConfig , IServiceProvider > config )
115
+ public static IServiceCollection AddCommandService ( this IServiceCollection collection , Action < CommandServiceConfig , IServiceProvider > config )
112
116
{
113
117
ArgumentNullException . ThrowIfNull ( config ) ;
114
118
@@ -119,27 +123,29 @@ public static void AddCommandService(this IServiceCollection collection, Action<
119
123
120
124
collection . AddSingleton < CommandService , InjectableCommandService > ( ) ;
121
125
collection . AddHostedService < CommandServiceRegistrationHost > ( ) ;
126
+
127
+ return collection ;
122
128
}
123
129
124
130
/// <summary>
125
131
/// Adds a <see cref="InteractionService"/> instance to the host for use with a Discord.NET client. />
126
132
/// </summary>
127
133
/// <param name="collection">The service collection to configure.</param>
128
134
/// <exception cref="InvalidOperationException">Thrown if <see cref="InteractionService"/> is already added to the collection</exception>
129
- public static void AddInteractionService ( this IServiceCollection collection ) => collection . AddInteractionService ( ( _ , _ ) => { } ) ;
135
+ public static IServiceCollection AddInteractionService ( this IServiceCollection collection ) => collection . AddInteractionService ( ( _ , _ ) => { } ) ;
130
136
131
137
132
138
/// <summary>
133
139
/// Adds a <see cref="InteractionService"/> instance to the host for use with a Discord.NET client. />
134
140
/// </summary>
135
141
/// <remarks>
136
- /// A <see cref="IServiceProvider"/> is supplied so you can pull data from additional services if required.
142
+ /// A <see cref="IServiceProvider"/> is supplied, so you can pull data from additional services if required.
137
143
/// </remarks>
138
144
/// <param name="collection">The service collection to configure.</param>
139
145
/// <param name="config">The delegate for configuring the <see cref="InteractionServiceConfig" /> that will be used to initialise the service.</param>
140
146
/// <exception cref="ArgumentNullException">Thrown if config is null</exception>
141
147
/// <exception cref="InvalidOperationException">Thrown if <see cref="InteractionService"/> is already added to the collection</exception>
142
- public static void AddInteractionService ( this IServiceCollection collection , Action < InteractionServiceConfig , IServiceProvider > config )
148
+ public static IServiceCollection AddInteractionService ( this IServiceCollection collection , Action < InteractionServiceConfig , IServiceProvider > config )
143
149
{
144
150
ArgumentNullException . ThrowIfNull ( config ) ;
145
151
@@ -150,6 +156,7 @@ public static void AddInteractionService(this IServiceCollection collection, Act
150
156
151
157
collection . AddSingleton < InteractionService , InjectableInteractionService > ( ) ;
152
158
collection . AddHostedService < InteractionServiceRegistrationHost > ( ) ;
153
-
159
+
160
+ return collection ;
154
161
}
155
- }
162
+ }
0 commit comments