As per my understanding, implementation of DI based on
1. ISampleInterface
2. Sample : ISampleInterface
3. Configuration Bind for ISampleInterface with Sample.
4. And Constructor injection
ISampleInterface _sampleInterface;
Constructor(ISampleInterface sampleInterface)
{
_sampleInterface = sampleInterface;
}
Rest of the thing handle by DI.
But if some case, within concrete Interface implementation class, it may be required to "New" Initialization. Then What Should I do ?
Within Sample class,
If I required to declare
private const int _limitSize = 70;
limits = new int[_limitSize];
Or within Sample class. bellow code may be required to write for Interface method implementation.
Dictionary<string, object[]> arr = new Dictionary<string, object[]>()
{
{"name", new string[1]{listName}},
};
Actual Implementation
public string ContactListsAdd(string listName)
{
Dictionary<string, object[]> arr = new Dictionary<string, object[]>()
{
{"name", new string[1]{listName}},
};
return callSomePrivateMethod("contact-lists.add", arr);
}
So My question is that, Is it a right approach to create object manually when we use DI. As per example. Or is their any way to avoid that ?