-1

I am learning ASP.NET Core and would like to perform a single asynchronous initialisation task before spawning background services. The initialisation task sets up kafka topics etc. based upon information in the appsettings.{Environment}.json config.

Is this best done in the Configure method of the Startup class? (See answer)

anon_dcs3spp
  • 2,342
  • 2
  • 28
  • 62
  • 3
    As you suggest, I do startup desalinization (like pre-load data in cache) in `Startup.Configure`. You can inject services as parameter. – vernou Nov 20 '20 at 17:15
  • Cheers, thanks @verno, appreciated :) – anon_dcs3spp Nov 20 '20 at 17:18
  • Assuming would have to something like suggested in this [article](https://andrewlock.net/running-async-tasks-on-app-startup-in-asp-net-core-3/) or [here](https://andrewlock.net/running-async-tasks-on-app-startup-in-asp-net-core-part-2/#an-example-async-database-migration) for initialisation task that is async? – anon_dcs3spp Nov 20 '20 at 18:13

1 Answers1

0

The task to setup the Kafka Topic is asynchronous and Startup.Configure is synchronous.

I eventually made the decision to use Thomas Levesque's Extensions.Hosting.AsyncInitialization to perform the Kafka topic creation.

For testing with xUnit and WebApplicationFactory I used a class fixture to perform the topic creation from test config before starting the WebApplicationFactory test server. See why here with a problem that I encountered with the test server blocking.

anon_dcs3spp
  • 2,342
  • 2
  • 28
  • 62