Reputation: 107
I have a class where I want to populate the model class properties. It works if I create a model class instance with new keyword. But this does not satisfy Dependency injection.
We also never pass a model object in the constructor as a parameter. How do we create the request object i.e. the model inside myClass without newing it up via DI?
This scenario is around bot framework.
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);
}
}
Upvotes: 1
Views: 460
Reputation: 3496
Model classes are normally not instanciated using Dependency Injection (DI). They are loaded from a service (read case) or created using new (create case). The service ist your depenendency that is injected via CI.
Upvotes: 1