diff --git a/.vscode/launch.json b/.vscode/launch.json index 4629cf1..9c5bec7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -4,6 +4,17 @@ // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md "version": "0.2.0", "configurations": [ + { + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + "program": "${workspaceFolder}/Apps/Sandbox/bin/Debug/net5.0/Sandbox.dll", + "args": [], + "cwd": "${workspaceFolder}/Apps/Sandbox", + "stopAtEntry": false, + "console": "internalConsole" + }, { "name": ".NET Core Launch (web)", "type": "coreclr", diff --git a/Apps/Sandbox/Program.cs b/Apps/Sandbox/Program.cs new file mode 100644 index 0000000..f7709c5 --- /dev/null +++ b/Apps/Sandbox/Program.cs @@ -0,0 +1,12 @@ +using System; + +namespace Sandbox +{ + class Program + { + static void Main(string[] args) + { + Console.WriteLine("Hey!"); + } + } +} diff --git a/Apps/Sandbox/Sandbox.csproj b/Apps/Sandbox/Sandbox.csproj new file mode 100644 index 0000000..2082704 --- /dev/null +++ b/Apps/Sandbox/Sandbox.csproj @@ -0,0 +1,8 @@ + + + + Exe + net5.0 + + + diff --git a/Infrastructure/ServiceCollectionExtensions.cs b/Infrastructure/ServiceCollectionExtensions.cs index 8e2cb94..6421402 100644 --- a/Infrastructure/ServiceCollectionExtensions.cs +++ b/Infrastructure/ServiceCollectionExtensions.cs @@ -5,6 +5,7 @@ using MyHN.Application; using MyHN.Domain; using MediatR; using MyHN.Infrastructure.Repositories; +using System; namespace MyHN.Infrastructure { @@ -41,7 +42,8 @@ namespace MyHN.Infrastructure , IConfiguration configuration) { services.AddDbContext(options => - options.UseSqlite(configuration.GetConnectionString("Default"))); + options.UseSqlite(configuration.GetOrParseConnectionString())); + services.AddScoped(); services.AddScoped(); services.AddScoped(); @@ -49,5 +51,21 @@ namespace MyHN.Infrastructure return new MyHNServicesBuilder(services); } + + private static string GetOrParseConnectionString(this IConfiguration configuration) + { + // Since it will be defined as an uri from heroku... + var envVar = Environment.GetEnvironmentVariable("DATABASE_URL"); + + if (string.IsNullOrWhiteSpace(envVar)) + { + return configuration.GetConnectionString("Default"); + } + + var uri = new Uri(envVar); + var userInfo = uri.UserInfo.Split(':'); + + return $"Host={uri.Host};Port={uri.Port};Database={uri.AbsolutePath.Substring(1)};Username={userInfo[0]};Password={userInfo[1]}"; + } } } \ No newline at end of file diff --git a/myhn.sln b/myhn.sln index cf9a7e2..a012416 100644 --- a/myhn.sln +++ b/myhn.sln @@ -17,6 +17,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Api", "Apps\Api\Api.csproj" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorClient", "Apps\BlazorClient\BlazorClient.csproj", "{A8CCBB1E-8161-4030-A4B6-299C7D589939}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Sandbox", "Apps\Sandbox\Sandbox.csproj", "{D21E8C20-42A0-4EDD-B6B2-31966C9D935C}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -111,6 +113,18 @@ Global {A8CCBB1E-8161-4030-A4B6-299C7D589939}.Release|x64.Build.0 = Release|Any CPU {A8CCBB1E-8161-4030-A4B6-299C7D589939}.Release|x86.ActiveCfg = Release|Any CPU {A8CCBB1E-8161-4030-A4B6-299C7D589939}.Release|x86.Build.0 = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|x64.ActiveCfg = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|x64.Build.0 = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|x86.ActiveCfg = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Debug|x86.Build.0 = Debug|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|Any CPU.Build.0 = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|x64.ActiveCfg = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|x64.Build.0 = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|x86.ActiveCfg = Release|Any CPU + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -122,5 +136,6 @@ Global {22BC27B6-608F-4DBB-9CDB-6A14D53A9BE3} = {55C05C83-8BEB-4FEC-B930-8DC161C99E7C} {7002AB9E-7457-4CE8-9368-AFD5A1F0119A} = {55C05C83-8BEB-4FEC-B930-8DC161C99E7C} {A8CCBB1E-8161-4030-A4B6-299C7D589939} = {55C05C83-8BEB-4FEC-B930-8DC161C99E7C} + {D21E8C20-42A0-4EDD-B6B2-31966C9D935C} = {55C05C83-8BEB-4FEC-B930-8DC161C99E7C} EndGlobalSection EndGlobal