I\'m new to C#/ASP coming from a Java world. I\'ve read this article: https://docs.asp.net/en/latest/fundamentals/dependency-injection.html#service-lifetimes-and-registratio
ok, found it:
public class Provider : IProvider {
IHttpContextAccessor contextAccessor;
public Provider(IHttpContextAccessor contextAccessor) {
this.contextAccessor = contextAccessor;
}
T IProvider.Get() {
return contextAccessor.HttpContext.RequestServices.GetService();
}
}
and in Startup:
public void ConfigureServices(IServiceCollection services) {
services.TryAddSingleton();
services.AddSingleton();
services.AddScoped();
services.AddTransient, Provider>();
// other bindings
}
:)
see https://github.com/aspnet/Hosting/issues/793 for more details about using and registering HttpContextAccessor