#How to do dep injection with the new Commands module

1 messages · Page 1 of 1 (latest)

flat hearth
#

So previously with CommandsNext you could use ServiceCollection, but it seems that is not the case anymore with the new Commands module that replaces CommandsNext & SlashCommands modules.

dry peak
#

It works still the same way, you provide the DiscordClient with your services and it gets used for the extensions

flat hearth
#

Ah, its the client

#

Are you sure it works the same?

dry peak
#

It should

flat hearth
#

Strange

#

It doesn't seem to

#

Or I am doing it wrong

#
        var services = new ServiceCollection()
            .AddSingleton<VoiceContext>();

        DiscordClientBuilder builder =
            DiscordClientBuilder.CreateDefault(Environment.GetEnvironmentVariable("DISCORD_TOKEN")!, intents, services);

This is how I am doing it now, as I notice its on the builder now.

and here is how i use it https://pastes.dev/9LOxxV6VAt

#

VoiceContext is my db context through efcore

dry peak
#

Commands are Singletons by default so you can't inject a scoped service like Ef core contexts

flat hearth
#

Alright

#

What do you recommend I do instead?