Search code examples
c#asp.net.netninject

What is the equivalent code for the ASP.NET Core DI framework from this example using Ninject and .toconstant?


I am migrating a project that used Ninject to another one that uses ASP.NET Core DI and I'm getting trouble when trying to inject this piece of code in Ninject:

Bind<PlayerService.PlayerServiceClient>()
                .ToConstant(new PlayerService.PlayerServiceClient(new Channel(Configuration.GetValue<string>("playerServiceEndpoint"), ChannelCredentials.Insecure)
                    .Intercept(new PrometheusClientInterceptor())));

How could I translate this?

Thanks you!


Solution

  • Okay I could make it work as follows:

    services.AddSingleton(new PlayerService.PlayerServiceClient(new Channel(Configuration.GetValue<string>("playerServiceEndpoint"), ChannelCredentials.Insecure)));