Skip to content

AsyncGuidance - Constructors and DI #63

Open
@mihirdilip

Description

@davidfowl, Constructors section explains getting around by using static factory pattern.

But, what happens when I cannot call this static method to create an instance because the instance is created by container when IService is dependency injected via constructor into other class?

Basically, what is the best practice for calling Async method in within constructor for these 2 different scenarios?

  • Need to wait for the Async method in ctor to finish before moving forward
  • Fire and forget to loading some collections asyncronously
    • I guess this will be similar to Async void i.e. Task.Run(BackgroundOperationAsync);?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions