libplanet
libplanet copied to clipboard
Replace `UserContext` with .NET DI
Looking at BlockType<T>.PreviousBlock, it asks to set IStore or BlockChain<T> via UserContext on Libplanet.Explorer.
However, this is something .NET DI can accomplish well enough. thus I suggest replacing it with DI like as below...
public BlockType(IStore store)
{
Field<BlockType<T>>(
"PreviousBlock",
resolve: ctx =>
{
if (!(ctx.Source.PreviousHash is BlockHash h))
{
return null;
}
HashAlgorithmGetter hashAlgorithmGetter = _ => HashAlgorithmType.Of<SHA256>();
return store.GetBlock<T>(hashAlgorithmGetter, h);
});
Name = "Block";
}
This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.
👀