Nethereum / Nethereum/Nethereum
Code generated services should use IWeb3 instead of Web3
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 2.3k
- Forks
- 744
- PR merge metrics
- No merged PRs in 30d
Description
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.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the code generator responsible for generated contract services and inspect how their constructors and Web3 properties are emitted. Verify that generated MyContractService instances accept an IWeb3 value without a cast, then validate the generated service behavior with the project's available tests or generation workflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- blockchain, tooling
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100