Skip to content

Instantly share code, notes, and snippets.

@jkone27
Created November 3, 2020 15:46
Show Gist options
  • Save jkone27/ec5040fbcaabadfb62b146876e328603 to your computer and use it in GitHub Desktop.
Save jkone27/ec5040fbcaabadfb62b146876e328603 to your computer and use it in GitHub Desktop.
WebApiComparisonStartupCsharp
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddControllers();
services.AddDbContext<PersonsContext>();
services.AddScoped<PersonsRepository>();
services.Configure<DbConfiguration>(Configuration.GetSection("DbConfiguration"));
services.Configure<ApiClientsConfig>(Configuration.GetSection("ApiClients"));
services.AddAutoMapper(Assembly.GetExecutingAssembly());
//client
services.AddHttpClient<PetsApiClient>();
//needed for swagger
services.AddMvc();
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
//hosted service
services.AddHostedService<PetsBackgroundJob>();
}
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseHttpsRedirection();
app.UseRouting();
app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapGet("/", context => context.Response.WriteAsync("Welcome to C#!"));
});
//needed for swagger
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment