jeudi 7 mai 2020

Initializing async rest api's instead of doing it in a constructor -c# .Net

I have to fetch some data through rest calls and cache them so that it can be used in the SDK i am working Just wanted to make sure if this is a correct approach or would like to know if it can be done in any better way

public class Library {

    private bool isInitialized;
    public Library(...dependencies) {}

    public async Task InitializeAsync() {
        if (!isInitialized) {
            var data1 = await "api call";
            var data2 = await "api call2";

            isInitialized = true
            //cache them
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire