Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rahulsahay19
Last active December 6, 2020 08:33
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 rahulsahay19/952f96fd60ba41583506766d404600c2 to your computer and use it in GitHub Desktop.
Save rahulsahay19/952f96fd60ba41583506766d404600c2 to your computer and use it in GitHub Desktop.
startup
using System.Reflection;
using AutoMapper;
using MediatR;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.OpenApi.Models;
using Movies.Application.Handlers;
using Movies.Core.Repositories;
using Movies.Core.Repositories.Base;
using Movies.Infrastructure.Data;
using Movies.Infrastructure.Repositories;
using Movies.Infrastructure.Repositories.Base;
namespace Movies.API
{
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.AddApiVersioning();
services.AddDbContext<MovieContext>(
m => m.UseSqlServer(Configuration.GetConnectionString("MovieConnection")), ServiceLifetime.Singleton);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "Movie Review API", Version = "v1" });
});
services.AddAutoMapper(typeof(Startup));
services.AddMediatR(typeof(CreateMovieHandler).GetTypeInfo().Assembly);
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
services.AddTransient<IMovieRepository, MovieRepository>();
}
// 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();
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Movie Review API V1");
});
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment