Skip to content

Commit

Permalink
Added UserSecrets
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaryn91 committed Apr 26, 2018
1 parent c96c022 commit 1f94a8d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
Expand Up @@ -14,12 +14,15 @@ namespace Musiction.API.BusinessLogic
public class PptxToJpgConverter
{
private Uri baseUri = new Uri("https://sandbox.zamzar.com/v1/");
private string _apiKey = Startup.Configuration["zamzarKey"];
private string _apiKey;
private IFileAndFolderPathsCreator _fileAndFolderPath;

public PptxToJpgConverter(IFileAndFolderPathsCreator fileAndFolderPath)
{
_fileAndFolderPath = fileAndFolderPath;

var propName = Startup.Configuration["environment"] + "ZamzarKey";
_apiKey = Startup.Configuration[propName];
}
public string Convert(string sourceFile)
{
Expand Down
2 changes: 2 additions & 0 deletions Musiction.API/Musiction.API/Musiction.API.csproj
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<UserSecretsId>79c7fe53-1b92-4bc2-ad7e-318e817f92c9</UserSecretsId>
</PropertyGroup>

<ItemGroup>
Expand All @@ -20,6 +21,7 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.Cors" Version="2.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.2" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="2.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="11.0.2" />
<PackageReference Include="NLog.Extensions.Logging" Version="1.0.0" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="2.0.1" />
Expand Down
24 changes: 17 additions & 7 deletions Musiction.API/Musiction.API/Program.cs
@@ -1,28 +1,38 @@
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using System.Collections.Generic;

namespace Musiction.API
{
public class Program
{
private static readonly Dictionary<string, string> defaults =
new Dictionary<string, string> { {
WebHostDefaults.EnvironmentKey, "development"
} };
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
public static IWebHost BuildWebHost(string[] args)
{

var element = WebHost.CreateDefaultBuilder(args)
.ConfigureAppConfiguration((webHostBuilderContext, configurationbuilder) =>
{
var environment = webHostBuilderContext.HostingEnvironment;
configurationbuilder
.AddJsonFile("appSettings.json", optional: false);
configurationbuilder.AddEnvironmentVariables();
configurationbuilder.AddJsonFile("appSettings.json", optional: false)
.AddInMemoryCollection(defaults)
.AddEnvironmentVariables("ASPNETCORE_")
.AddCommandLine(args)
.AddUserSecrets<Startup>();
})
.UseStartup<Startup>()
.Build();

return element;
}
}
}
6 changes: 3 additions & 3 deletions Musiction.API/Musiction.API/Startup.cs
Expand Up @@ -48,7 +48,9 @@ public void ConfigureServices(IServiceCollection services)

services.AddTransient<IMailService, LocalMailService>();

var connectionString = Startup.Configuration["connectionStrings"];
var propName = Startup.Configuration["environment"] + "ConnectionString";
var connectionString = Startup.Configuration[propName];

services.AddDbContext<SongContext>(o => o.UseMySql(connectionString));

services.AddScoped<ISongRepository, SongRepository>();
Expand All @@ -64,8 +66,6 @@ public void ConfigureServices(IServiceCollection services)
loggerFactory.AddDebug();
loggerFactory.AddNLog();



songContext.EnsureSeedDataForContext();

if (env.IsDevelopment())
Expand Down

0 comments on commit 1f94a8d

Please sign in to comment.