Add Startup.cs file
This commit is contained in:
53
src/Printbase.WebApi/Startup.cs
Normal file
53
src/Printbase.WebApi/Startup.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using System.Reflection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Printbase.Domain.Repositories;
|
||||
using Printbase.Infrastructure.Database;
|
||||
using Printbase.Infrastructure.Mapping;
|
||||
using Printbase.Infrastructure.Repositories;
|
||||
|
||||
namespace Printbase.WebApi;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public static void ConfigureServices(WebApplicationBuilder builder)
|
||||
{
|
||||
var services = builder.Services;
|
||||
|
||||
services.AddDbContext<ApplicationDbContext>(options =>
|
||||
options.UseSqlServer(
|
||||
builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||
b => b.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName)));
|
||||
|
||||
services.AddMediatR(cfg => cfg.RegisterServicesFromAssembly(Assembly.GetExecutingAssembly()));
|
||||
|
||||
services.AddScoped<IProductRepository, ProductRepository>();
|
||||
services.AddScoped<IProductVariantRepository, ProductVariantRepository>();
|
||||
services.AddScoped<IProductTypeRepository, ProductTypeRepository>();
|
||||
services.AddScoped<IProductGroupRepository, ProductGroupRepository>();
|
||||
|
||||
services.AddAutoMapper(typeof(ProductMappingProfile).Assembly);
|
||||
|
||||
services.AddOpenApi();
|
||||
}
|
||||
|
||||
public static void Configure(IApplicationBuilder app, IWebHostEnvironment env)
|
||||
{
|
||||
if (env.IsDevelopment())
|
||||
{
|
||||
app.UseDeveloperExceptionPage();
|
||||
}
|
||||
else
|
||||
{
|
||||
app.UseExceptionHandler("/Error");
|
||||
app.UseHsts();
|
||||
app.UseHttpsRedirection();
|
||||
}
|
||||
|
||||
app.UseRouting();
|
||||
|
||||
app.UseEndpoints(endpoints =>
|
||||
{
|
||||
endpoints.MapControllers();
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user