Click or drag to resize

How To Asynchronously Resolve a Type

This topic details the steps necessary for asynchronously resolving a type from a Unity container.

  1. Make sure the resolved type is registered with the container, either directly or as the target type in a mapping .

    This example assumes a prior registration of a mapping of IUniversalAnswerService to UniversalAnswerService.

  2. Import the Unity Container Async Extensions namespace:

    C#
    using Ditto.AsyncInit.Unity;
  3. Resolve the type asynchronously:

    C#
    var service = await container.ResolveAsync<IUniversalAnswerService>(cancellationToken);
    var answer = service.Answer;

Unity Container Async Extensions provide support for advanced resolution scenarios through overloads of ResolveAsync.

See Also