The WebApplication.Start
method has an overload that accepts a IServiceProvider
as parameter, so it is possible to inject the data I want.
IServiceProvider serviceProvider = DefaultServices.Create(defaultServiceProvider =>
{
defaultServiceProvider.AddInstance<IMyInterface>(myInstance);
});
using (WebApplication.Start<Startup>(serviceProvider, url)){ ... }
Now, on my Startup
class I only need to create a constructor that receives the IMyInterface:
public Startup(IMyInterface myInstance)
{
...
}