-
Notifications
You must be signed in to change notification settings - Fork 494
Annotations Framework - does this have access to an IHostEnvironment ? #1517
-
👋🏻 G'Day team!
With the Annotations Framework, we can register services into the DI container.
e.g.
[LambdaStartup]
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
// Prepare our configuration data.
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false)
.AddJsonFile($"appsettings.{????}.json", optional: false)
.AddEnvironmentVariables();
var configuration = builder.Build();
services.AddSingleton<IConfiguration>(configuration);
services.AddSingleton<IDatabase>(implementationInstance =>
{
// Logic here
});
// Register more services, if required.
}
}
But in the code above, I was hoping to access if the HostEnvironment that I'm familiar with in a normal ASP.NET Core API project : Development or Production (for example).
Is this available here, in Annotation Framework or even in Lambda's in general?
I understand that the value of the host environment is a number of Environment Variables (like ASPNETCORE_ENVIRONMENT) so I could probably try and manually see if that exists (not sure how?).
But yeah - is this possible or not?
Thank you kindly.
Beta Was this translation helpful? Give feedback.
All reactions
@PureKrome Good morning. Based on my understanding, the Lambda Annotations framework uses C# source generators to create the translation layer at compile time.
It uses FieldAndConstructor TT template to emit constructor for the generated type, where it includes a statement to invoke the Startup type's (class decorated with LambdaStartupAttribute) ConfigureServices(IServiceCollection) method.
My assumption is that during deployment, you could set the environment variable ASPNETCORE_ENVIRONMENT to appropriate value and should be able to read it in your code.
CC @normj
Thanks,
Ashish
Replies: 2 comments
-
@PureKrome Good morning. Based on my understanding, the Lambda Annotations framework uses C# source generators to create the translation layer at compile time.
It uses FieldAndConstructor TT template to emit constructor for the generated type, where it includes a statement to invoke the Startup type's (class decorated with LambdaStartupAttribute) ConfigureServices(IServiceCollection) method.
My assumption is that during deployment, you could set the environment variable ASPNETCORE_ENVIRONMENT to appropriate value and should be able to read it in your code.
CC @normj
Thanks,
Ashish
Beta Was this translation helpful? Give feedback.
All reactions
-
Hello! Reopening this discussion to make it searchable.
Beta Was this translation helpful? Give feedback.