LightInject icon indicating copy to clipboard operation
LightInject copied to clipboard

Async LightInject: adding async CompositionRoots

Open moswald opened this issue 9 years ago • 2 comments
trafficstars

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.

moswald avatar Feb 02 '16 15:02 moswald

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.

seesharper avatar Feb 04 '16 08:02 seesharper

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.

moswald avatar Feb 05 '16 14:02 moswald