I have a class A. It must be a singleton and the async Initialization method must be called when it is created. I did not find suitable functionality in the DryIoc documentation. It seems to me that the RegisterDelegate method is the closest, but it does not take an asynchronous lambda as a parameter.
For clarity, I will give an example to be in front of your eyes:
public class A
{
...
public async Task<A> Initialization() {...}
...
}
var instance = await new A().Initialization();
Answer 1
The
asyncinitialization is not yet supported by the DryIoc because of the two-colored function problem and the associated complexity.Basically, I need to introduce the separate
awaitcall graph generated for the whole chain of dependencies where some of them areasyncstarting from theResolveAsyncor similar API.In the absence of it, you may use the approach discussed at the end of the article https://endjin.com/blog/2023/01/dotnet-csharp-lazy-async-initialization.
In this approach, you are moving the await part of the initialization outside the construction phase into the method(s).
So you may add the async Initialization as a Func dependency into the constructor:
Answer 2
You may go full manual mode, which appears much simpler to me. Call the
Initializationmanually before the first use.Feedback
I am very interested on any ideas for this topic as well as for the alternative solutions.