Skip to content

Instantly share code, notes, and snippets.

@glennc
Created November 7, 2018 05:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glennc/953e2e805d813279153175521abe7bc1 to your computer and use it in GitHub Desktop.
Save glennc/953e2e805d813279153175521abe7bc1 to your computer and use it in GitHub Desktop.
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