Code generated services should use IWeb3 instead of Web3
Use of interfaces in constructors is compliant to best IoC practices.
Currently generated contract services receive and use instead the Web3 implementation. Because this, it's impossible, without an ugly cast, to create an instance of these with only an IWeb3 instance.
Expected Behavior
I'd like to be able to use my IoC system for receive an IWeb3 instance inside my service, and with this be able to instantiate a new generated MyContractService.
Example:
class MyService
{
private readonly IWeb3 web3;
public MyService(IWeb3 web3)
{
this.web3 = web3;
}
public void DoStuff()
{
var myContractService = new MyContractService(web3, "0x123456ABCD");
// ...
}
}
/* Generated code */
public partial class MyContractService
{
protected Nethereum.Web3.IWeb3 Web3 { get; }
public MyContractService(Nethereum.Web3.IWeb3 web3, string contractAddress)
{
Web3 = web3;
ContractHandler = web3.Eth.GetContractHandler(contractAddress);
}
// ....
}
Current Behavior
At now I need to perform a cast.
class MyService
{
private readonly IWeb3 web3;
public MyService(IWeb3 web3)
{
this.web3 = web3;
}
public void DoStuff()
{
var myContractService = new MyContractService(web3 as Web3, "0x123456ABCD");
// ...
}
}
Detailed Description
Replace on code generator the use of Web3 with use of IWeb3 inside generated services.
Yes makes sense, the level of abstraction at the moment to support IoC is too low level at TransactionHandler, QueryHandler not to use the service but the CQS pattern. (Not easy to guess that one)