Code Monkey home page Code Monkey logo

Comments (4)

Mijago avatar Mijago commented on June 18, 2024

This gives me another question:
I add my ILogger to my provider by using .AddLogging(builder => builder.AddConsole()) (for testing etc.).

Then I register Lavalink-related stuff using:

.AddSingleton<IAudioService, LavalinkNode>()
.AddSingleton<IDiscordClientWrapper, DiscordClientWrapper>()
.AddSingleton(new LavalinkNodeOptions
{
    RestUri = "http://lavalink:8080/",
    WebSocketUri = "ws://lavalink:8080/",
    Password = "youshallnotpass",
    AllowResuming = false // (btw, I can pause/resume despite this setting)
})
.AddSingleton<InactivityTrackingOptions>() // This is new
.AddSingleton<InactivityTrackingService>() // This is new, too

So my question is: How do I get the logger to the LavalinkNode instance when using DI?

Offtopic:
By the way, good work on this library! I enjoy working with it.

from lavalink4net.

angelobreuer avatar angelobreuer commented on June 18, 2024

The problem is with Dependency Injection, for example when creating the instance of InactivityTrackingService using its constructor the issue is solved, I added to the 1.3.0-release milestone adding service provider constructors (or constructors without the optional parameters) for use with dependency injection.

As a "work-around" you could use the constructor of the InactivityTrackingService to avoid the ILogger as shown below:

new ServiceCollection()
    // [...] adding client wrapper, etc.
    .AddSingleton(sp => new InactivityTrackingService(sp.GetRequiredService<IAudioService>(),
        sp.GetRequiredService<IDiscordClientWrapper>(),
        sp.GetRequiredService<InactivityTrackingOptions>(),
        null))
    // [...]
    .BuildServiceProvider();

from lavalink4net.

angelobreuer avatar angelobreuer commented on June 18, 2024

This gives me another question:
I add my ILogger to my provider by using .AddLogging(builder => builder.AddConsole()) (for testing etc.).

Then I register Lavalink-related stuff using:

.AddSingleton<IAudioService, LavalinkNode>()
.AddSingleton<IDiscordClientWrapper, DiscordClientWrapper>()
.AddSingleton(new LavalinkNodeOptions
{
    RestUri = "http://lavalink:8080/",
    WebSocketUri = "ws://lavalink:8080/",
    Password = "youshallnotpass",
    AllowResuming = false // (btw, I can pause/resume despite this setting)
})
.AddSingleton<InactivityTrackingOptions>() // This is new
.AddSingleton<InactivityTrackingService>() // This is new, too

So my question is: How do I get the logger to the LavalinkNode instance when using DI?

Offtopic:
By the way, good work on this library! I enjoy working with it.

The ILogger-interface used by Lavalink4NET is not from Microsoft.Extensions.Logging(.Abstractions) anymore (since version 1.2.0, to remove the dependency).

See: https://github.com/angelobreuer/Lavalink4NET/blob/master/samples/Lavalink4NET.Discord_NET.ExampleBot/CustomLogger.cs for an example implementation of the interface. (It must be also added to the dependency injection service provider)


By the way:

AllowResuming = false // (btw, I can pause/resume despite this setting)

A note on this setting, this setting enables the session resume after reconnecting to the lavalink node to keep the player data (enqueued songs, etc.). Disabling the option will disconnect all players when stopping the bot.

from lavalink4net.

angelobreuer avatar angelobreuer commented on June 18, 2024

Hope the issue is fixed now with #8, release version 1.3.0 is now available (also on NuGet).

from lavalink4net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.