Skip to content

Commit

Permalink
Two solutions with code written so far. In the course, we're currentl…
Browse files Browse the repository at this point in the history
…y at Building Your First ASP.NET Core Application > Creating and Injecting Greeting Service.
  • Loading branch information
gorohoroh committed Jul 3, 2018
1 parent ad39c00 commit a5219b1
Show file tree
Hide file tree
Showing 14 changed files with 273 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ BenchmarkDotNet.Artifacts/
project.lock.json
project.fragment.lock.json
artifacts/
**/Properties/launchSettings.json

# StyleCop
StyleCopReport.xml
Expand Down
16 changes: 16 additions & 0 deletions OdeToFoodRider/OdeToFoodRider.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OdeToFoodRider", "OdeToFoodRider\OdeToFoodRider.csproj", "{570AED0D-E198-4308-8F55-EB8E8473A26B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{570AED0D-E198-4308-8F55-EB8E8473A26B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{570AED0D-E198-4308-8F55-EB8E8473A26B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{570AED0D-E198-4308-8F55-EB8E8473A26B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{570AED0D-E198-4308-8F55-EB8E8473A26B}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
EndGlobal
16 changes: 16 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/IGreeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
namespace OdeToFoodRider
{
public interface IGreeter
{
string GetMessageOfTheDay();
}

class Greeter : IGreeter
{
public string GetMessageOfTheDay()
{
throw new System.NotImplementedException();

}
}
}
15 changes: 15 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/OdeToFoodRider.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace OdeToFoodRider
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
36 changes: 36 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace OdeToFoodRider
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IGreeter greeter)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
var greeting = greeter.GetMessageOfTheDay();
await context.Response.WriteAsync(greeting);
});
}
}
}
7 changes: 7 additions & 0 deletions OdeToFoodRider/OdeToFoodRider/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"Greeting": "Hello from Rider",
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;MultipleActiveResultSets=true"
}

}
25 changes: 25 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OdeToFoodVisualStudio", "OdeToFoodVisualStudio\OdeToFoodVisualStudio.csproj", "{4F4A0317-B875-4C01-BF86-03CD0C50ADE5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4F4A0317-B875-4C01-BF86-03CD0C50ADE5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F4A0317-B875-4C01-BF86-03CD0C50ADE5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F4A0317-B875-4C01-BF86-03CD0C50ADE5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F4A0317-B875-4C01-BF86-03CD0C50ADE5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {80C422F9-E0BD-42BA-A7A5-543E9543B10A}
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace OdeToFoodVisualStudio
{
public interface IGreeter
{
string GetMessageOfTheDay();
}

// VSvsRider: Visual Studio does allow implementing IGreeter from usage when the Greeter class has been declared; however, Rider does have the advantage of providing the "Create derived type"
// context action upon the IGreeter declaration.
// Presentation: proceed in "Creating and injecting greeting service" at 1:25
class Greeter : IGreeter
{
public string GetMessageOfTheDay()
{
throw new System.NotImplementedException();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.8" />
</ItemGroup>

</Project>
25 changes: 25 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace OdeToFoodVisualStudio
{
public class Program
{
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}

public static IWebHost BuildWebHost(string[] args) =>
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
.Build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:54448/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"OdeToFoodVisualStudio": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:54449/"
}
}
}
42 changes: 42 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;

namespace OdeToFoodVisualStudio
{
public class Startup
{
// This method gets called by the runtime. Use this method to add services to the container.
// For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
public void ConfigureServices(IServiceCollection services)
{
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env, IGreeter greeter)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}

app.Run(async (context) =>
{
// Configuration sources by descending priority: 1. command-line parameter, 2. environment variable, 3. appsettings.json (enables storing dev settings in appsettings.json and overriding them in production wtih environment variables for example)
// VsvsRider: doesn look like there's an action to add a new comment (there are actions to comment/decomment existing code; and to add documentation comment)
// VsvsRider: VS create from usage isn't quite on par right now: given the undeclared IGreeter interface in method parameteres and the below line that uses an undeclared method,
// <strike>1. You must create the interface from usage first, and only then can you create the method - so there's no chaining in Create from Usage;</strike> - same in Rider :(
// 2. The created symbol doesn't get focus: both when it's created in a separate file and when it's created in the same file
// 3. Roslyn doesn't infer that the generated method should return a string, not an object
var greeting = greeter.GetMessageOfTheDay();
await context.Response.WriteAsync(greeting);
});
}
}

}
6 changes: 6 additions & 0 deletions OdeToFoodVisualStudio/OdeToFoodVisualStudio/appsettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"Greeting": "Hello from Visual Studio",
"ConnectionStrings": {
"DefaultConnection": "Server=(localdb)\\MSSQLLocalDB;Database=_CHANGE_ME;Trusted_Connection=True;MultipleActiveResultSets=true"
}
}

0 comments on commit a5219b1

Please sign in to comment.