Last active
May 20, 2020 13:11
-
-
Save benaadams/f8f5b3ea3354643b954f102fb778f191 to your computer and use it in GitHub Desktop.
Microservice Lib + App
This file contains 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 Microsoft.AspNetCore; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.DependencyInjection; | |
using System; | |
namespace MicroserviceLib | |
{ | |
public class Microservice : Controller, IStartup | |
{ | |
public static void Run<TStartup>(string[] args) where TStartup : class | |
=> WebHost.CreateDefaultBuilder(args) | |
.UseStartup<TStartup>() | |
.Build().Run(); | |
IServiceProvider IStartup.ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc(); | |
return services.BuildServiceProvider(); | |
} | |
void IStartup.Configure(IApplicationBuilder app) | |
=> app.UseMvc(); | |
} | |
} |
This file contains 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 Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Logging; | |
using MicroserviceLib; | |
public class Program : Microservice | |
{ | |
private ILogger<Program> _log; | |
public Program(ILogger<Program> log) | |
{ | |
_log = log; | |
} | |
[HttpGet("/")] | |
public string Hello() | |
{ | |
_log.LogInformation("Two lines made me add brackets 😢"); | |
return "Hello World"; | |
} | |
public static void Main(string[] args) | |
=> Run<Program>(args); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment