此示例中使用 Ninject 和 .toconstant 的 ASP.NET Core DI 框架的等效代码是什么?

问题描述 投票:0回答:1

我正在将一个使用 Ninject 的项目迁移到另一个使用 ASP.NET Core DI 的项目,当我试图在 Ninject 中注入这段代码时遇到了麻烦:

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

我怎么翻译这个?

谢谢!

c# asp.net .net ninject
1个回答
0
投票

好吧,我可以让它按如下方式工作:

services.AddSingleton(new PlayerService.PlayerServiceClient(new Channel(Configuration.GetValue<string>("playerServiceEndpoint"), ChannelCredentials.Insecure)));
© www.soinside.com 2019 - 2024. All rights reserved.