小编Osc*_*uez的帖子

使用默认的 ASP.NET Core DI 容器在 Service Fabric 上设置依赖注入

我想使用 ASP.NET Core 的默认 DI 容器来为我的 Service Fabric 项目设置 DI。

//This is what I've got so far, and it works great
ServiceRuntime.RegisterServiceAsync(
  "MyServiceType",
  context => new MyService(context, new MyMonitor()
).GetAwaiter().GetResult();

//This is how I use it
public MyService(StatefulServiceContext context, IMonitor myMonitor)
  : base(context)
{
  this._myMonitor = myMonitor;           
}
Run Code Online (Sandbox Code Playgroud)

如果MyMonitor类依赖于ConfigProvider类,我将如何设置 DI ,如下所示:

public MyMonitor(IConfigProvider configProvider)
{
  this._configProvider = configProvider;
}
Run Code Online (Sandbox Code Playgroud)

dependency-injection .net-core azure-service-fabric

3
推荐指数
1
解决办法
3147
查看次数