From 972408e215db8f217a500e7c7ee4ecfe8353eecf Mon Sep 17 00:00:00 2001 From: gorohoroh Date: Tue, 3 Jul 2018 15:47:53 +0300 Subject: [PATCH] Completing a basic IGreeter service and configuring ASP.NET Core to instantiate a Greeter class any time an IGreeter is injected --- OdeToFoodRider/OdeToFoodRider/IGreeter.cs | 2 +- OdeToFoodRider/OdeToFoodRider/Startup.cs | 2 ++ OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs | 2 +- OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs | 7 +++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/OdeToFoodRider/OdeToFoodRider/IGreeter.cs b/OdeToFoodRider/OdeToFoodRider/IGreeter.cs index 18e4670..899542a 100644 --- a/OdeToFoodRider/OdeToFoodRider/IGreeter.cs +++ b/OdeToFoodRider/OdeToFoodRider/IGreeter.cs @@ -9,7 +9,7 @@ class Greeter : IGreeter { public string GetMessageOfTheDay() { - throw new System.NotImplementedException(); + return "Greetings from Rider!"; } } diff --git a/OdeToFoodRider/OdeToFoodRider/Startup.cs b/OdeToFoodRider/OdeToFoodRider/Startup.cs index e4ba6e9..2b23fdd 100644 --- a/OdeToFoodRider/OdeToFoodRider/Startup.cs +++ b/OdeToFoodRider/OdeToFoodRider/Startup.cs @@ -16,6 +16,8 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + services.AddSingleton(); + } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. diff --git a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs index 1c66f2f..9b94fee 100644 --- a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs +++ b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/IGreeter.cs @@ -12,7 +12,7 @@ class Greeter : IGreeter { public string GetMessageOfTheDay() { - throw new System.NotImplementedException(); + return "Greetings from Visual Studio!"; } } } \ No newline at end of file diff --git a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs index 2d3c92e..102a035 100644 --- a/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs +++ b/OdeToFoodVisualStudio/OdeToFoodVisualStudio/Startup.cs @@ -12,6 +12,9 @@ public class Startup // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { + // RDVS: Rider's completion works better with this generic method as it additionally adds the parentheses; additionally, VS overlaps the completion list inside the generic brackets + // with with parameter info + services.AddSingleton(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -26,8 +29,8 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env, IGreeter { // 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, + // RDVS: 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) + // RDVS: 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, // 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; - 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