LightInject
LightInject copied to clipboard
Async LightInject: adding async CompositionRoots
This is going to be the first of a series of Pull Requests to enable asynchronous initialization of the LightInject ServiceContainer.
This first one is a small step, adding an asynchronous version of RegisterFrom, as that touches the least amount of code, causes no breaking changes, and covers what is (if I were to guess) the most common case.
RegisterFromAsync<TAsyncCompositionRoot>() is a counterpart to the current RegisterFrom<TCompositionRoot>(). TAsyncCompositionRoot is a type that must derive from the new IAsyncCompositionRoot.
Looks great. I have just one question though. Given that we are talking about a web application with a startup class or a console application with a main method, how should the RegisterFromAsync method be invoked without doing somthing like
container.RegisterFromAsync<MyAsyncCompositionRoot>().Wait();
Most .Net applications does not support async initialization and that is usually where we put the initialization code for the container.
Sorry, I've been a bit under the weather and haven't been paying attention to github stuff the past few days.
In my specific case that spawned this PR, I've got a console-like app that spawns an async service in the Main method, and calls myService.RunAsync().Wait() at that point already.