Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rewrite DSharp plus to use Actions and Functions instead initializing classes #1712

Open
RosenDev opened this issue Dec 28, 2023 · 8 comments
Assignees
Labels
commands For issues related to DSharpPlus.Commands commands-next For issues related to DSharpPlus.CommandsNext enhancement

Comments

@RosenDev
Copy link

What is the problem: Now with existing logic a command module/class is initialize once and its lifetime is singleton until the application is shut down. This leads to the need to register all our services as singleton which is not wanted behavior in most scenarios.

If we use the attribute and change the command lifetime to transient each time a new command is received the module will be instantiated which is completely no sense as only the method in the class is used.

With usage of functions and actions we can pass dependencies directly to the function with any lifetime.

@OoLunar OoLunar self-assigned this Dec 28, 2023
@OoLunar
Copy link
Member

OoLunar commented Dec 28, 2023

Hey, thanks for opening up an issue!

Could we get a little bit more information? This sounds like you're working with a command framework. Is this with CommandsNext or SlashCommands? Secondly, could we get a small code example of what you're currently doing and how the behavior is different from what you're expecting?

@Plerx2493
Copy link
Member

Is this with CommandsNext? We provide support for a Scoped lifetime in our SlashCommands framework

@RosenDev
Copy link
Author

Is this with CommandsNext? We provide support for a Scoped lifetime in our SlashCommands framework

Yes its connected with command next but there is no issue with the lifetime. Its an improvement of the structure of the code.

@Plerx2493
Copy link
Member

Can you specifiy what api/internal change you would want?

@RosenDev
Copy link
Author

Can you specifiy what api/internal change you would want?

Well sorry for the delay i was just figuring out how it will happen with the command context.

Here is example code leave your feedback if its possible to implement.

`
var registeredCommandSources = new Dictionary<string, Func<IServiceProvider, CommandContext, string[], Task>>();

        //adding a command example

        Func<IServiceProvider, CommandContext, string[], Task> hiCommandSource = (sp, ctx, args) => { return ctx.RespondAsync("Hi"); };


        registeredCommandSources.Add("commandName", hiCommandSource);


        //executing the command

        //just for the example in real situation real values should be passed
        var serviceProvider = new ServiceCollection().BuildServiceProvider();

        await registeredCommandSources["commandName"](serviceProvider, null, new string[3]);`

@RosenDev
Copy link
Author

Hey, thanks for opening up an issue!

Could we get a little bit more information? This sounds like you're working with a command framework. Is this with CommandsNext or SlashCommands? Secondly, could we get a small code example of what you're currently doing and how the behavior is different from what you're expecting?

Hi I provided an example of what I meant in my comment. Its my latest reply to Plerx2493

@Plerx2493 Plerx2493 added the commands-next For issues related to DSharpPlus.CommandsNext label Dec 28, 2023
@akiraveliara
Copy link
Member

we have plans for a similar feature, albeit slightly different for technical reasons. it'll probably be tested soon-ish and published to nightly thereafter.

that said, please also avoid cross-linking unrelated issues

@RosenDev
Copy link
Author

we have plans for a similar feature, albeit slightly different for technical reasons. it'll probably be tested soon-ish and published to nightly thereafter.

that said, please also avoid cross-linking unrelated issues

Sorry didn't saw the last comment and accidently linked this one. Removed my comment for your issue you can unlink it.

Best regards,

Rosen

@akiraveliara akiraveliara added the commands For issues related to DSharpPlus.Commands label May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
commands For issues related to DSharpPlus.Commands commands-next For issues related to DSharpPlus.CommandsNext enhancement
Projects
None yet
Development

No branches or pull requests

4 participants