【发布时间】:2021-04-17 03:21:14
【问题描述】:
我有一个要填充模型类属性的类。如果我使用 new 关键字创建模型类实例,它会起作用。但这并不能满足依赖注入。
我们也从不在构造函数中传递模型对象作为参数。我们如何在不通过 DI 更新的情况下创建请求对象,即 myClass 中的模型?
这个场景是围绕机器人框架。
public class myDailog : ComponentDialog
{
private readonly modelClass _req;
private readonly serviceClass _sev
public myDialog(IServiceProvider serviceProvider)
: base(nameof(myDialog))
{
_sev = serviceProvider;
modelClass _req = new modelClass();
}
public async Task<DialogTurnResult> method1()
{
req.name = "something";
req.desc = "some description";
// pass the req object to another service
_sev.somemethod(req);
}
}
【问题讨论】:
标签: c# dependency-injection botframework