Skip to content
Permalink
Browse files

Working Environment Variables

  • Loading branch information...
garywoodfine committed Apr 25, 2019
1 parent 0e97339 commit 4a69df1b028f480f8865e6d8628560977f79e096
Showing with 18 additions and 14 deletions.
  1. +3 −3 src/Functions/Speak.cs
  2. +2 −4 src/LambdaConfiguration.cs
  3. +7 −2 src/Services/SpeakService.cs
  4. +2 −1 src/StartUp.cs
  5. +2 −2 src/appsettings.json
  6. +2 −2 src/serverless.yml
@@ -8,17 +8,17 @@ namespace Threenine.ConfigTest.Functions
public class Speak
{
private readonly IServiceProvider _serviceProvider;

public Speak(IServiceProvider serviceProvider)
{
_serviceProvider = serviceProvider;
}

public Speak() : this(StartUp.Container.BuildServiceProvider())
{

}
[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]

[LambdaSerializer(typeof(Amazon.Lambda.Serialization.Json.JsonSerializer))]
public string Greet(ILambdaContext context)
{
var talk = _serviceProvider.GetService<ISpeakService>();
@@ -1,18 +1,16 @@
using System.IO;
using Microsoft.Extensions.Configuration;


namespace Threenine.ConfigTest
{
public class LambdaConfiguration : ILambdaConfiguration
public class LambdaConfiguration : ILambdaConfiguration
{
public static IConfigurationRoot Configuration => new ConfigurationBuilder()
public static IConfigurationRoot Configuration => new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();


IConfigurationRoot ILambdaConfiguration.Configuration => Configuration;
}
}
@@ -1,15 +1,20 @@
using Microsoft.Extensions.Options;
using Threenine.ConfigTest.Config;

namespace Threenine.ConfigTest.Services
{
public class SpeakService : ISpeakService
{
private readonly Greeting _greeting;
public SpeakService(IOptions<Greeting> hello)
private readonly SpeakEnvironment _speakEnvironment;

public SpeakService(IOptions<Greeting> hello, IOptions<SpeakEnvironment> speakEnvironment)
{
_greeting = hello.Value;
_speakEnvironment = speakEnvironment.Value;

}

public string Greeting => _greeting.Message;
public string Greeting => string.Concat( _greeting.Message, " ", _speakEnvironment.SaySomething);
}
}
@@ -1,5 +1,6 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Threenine.ConfigTest.Config;
using Threenine.ConfigTest.Services;

namespace Threenine.ConfigTest
@@ -16,7 +17,7 @@ private static IServiceCollection ConfigureServices(IConfigurationRoot root)
root.GetSection("greeting").Bind(options));

services.AddTransient<ISpeakService, SpeakService>();

services.Configure<SpeakEnvironment>(options => root.GetSection("SpeakEnvironment").Bind(options));
return services;

}
@@ -1,5 +1,5 @@
{
"Greeting" : {
"message": "This is from the configuration"
"greeting" : {
"message": "Hello, "
}
}
@@ -4,8 +4,8 @@ provider:
name: aws
runtime: dotnetcore2.1
environment:
SpeakEnvironment__SaySomething: "Eating Coconuts is cool"

SpeakEnvironment__SaySomething: "Eating coconuts is cool"
package:
individually: true

0 comments on commit 4a69df1

Please sign in to comment.
You can’t perform that action at this time.