Created
November 7, 2018 05:39
-
-
Save glennc/953e2e805d813279153175521abe7bc1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.AspNetCore.Builder; | |
namespace WebApplication19 | |
{ | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
CreateWebHostBuilder(args).Build().Run(); | |
} | |
public static IWebHostBuilder CreateWebHostBuilder(string[] args) => | |
WebHost.CreateDefaultBuilder(args) | |
.ConfigureServices(s => s.AddSingleton<SingleService>()) | |
.UseStartup<Startup>(); | |
} | |
public class SingleService | |
{ | |
public Guid Id { get; set; } | |
public SingleService() | |
{ | |
Id = Guid.NewGuid(); | |
} | |
} | |
public class Startup | |
{ | |
public Startup(SingleService service) | |
{ | |
Console.WriteLine(service.Id); | |
} | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, SingleService service) | |
{ | |
Console.WriteLine(service.Id); | |
app.UseMvc(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment