渴望在ASP.net Core 3.1中加载GRPC端点



有没有一种方法可以急切地加载GRPC端点,以便在应用程序启动时解析类的服务?我目前注册GRPC端点如下:

public class Startup {
...
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapGrpcService<GrpcEndpointImpl>();
... More endpoints
});
}
}
public class GrpcEndpointImpl() {
public GrpcEndpointImpl(ExampleService service) {
....
}
}

我希望在启动应用程序后立即解决ExampleService。我在文件中找不到任何信息。我看了看。欢迎提出任何建议。

致以最良好的问候。

我最终在我的Configure方法中解决了类的依赖关系,如下所示:

public class Startup {
...
public void Configure(IApplicationBuilder app, IWebHostEnvironment env) {
if (env.IsDevelopment()) {
app.UseDeveloperExceptionPage();
}
app.UseRouting();
app.UseEndpoints(endpoints => {
endpoints.MapGrpcService<GrpcEndpointImpl>();
... More endpoints
});
app.ApplicationServices.GetService<ExampleService>(); // Note this line here
}
}
public class GrpcEndpointImpl() {
public GrpcEndpointImpl(ExampleService service) {
....
}
}

最新更新