From c69d193d050aa4821c74a834ff6d810ca5cee541 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentina=20Cupa=C4=87?= Date: Sat, 18 Jun 2022 18:45:34 +0200 Subject: [PATCH] Refactoring --- .../IServiceCollectionExtensions.cs | 36 +++++++++++++++++++ src/Optivem.Kata.Banking.Web/Program.cs | 28 ++------------- 2 files changed, 38 insertions(+), 26 deletions(-) create mode 100644 src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs diff --git a/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs b/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs new file mode 100644 index 0000000..b6ceb40 --- /dev/null +++ b/src/Optivem.Kata.Banking.Web/Extensions/IServiceCollectionExtensions.cs @@ -0,0 +1,36 @@ +using MediatR; +using Microsoft.EntityFrameworkCore; +using Optivem.Kata.Banking.Core; +using Optivem.Kata.Banking.Core.Domain.BankAccounts; +using Optivem.Kata.Banking.Core.Domain.Time; +using Optivem.Kata.Banking.Infrastructure; +using Optivem.Kata.Banking.Infrastructure.Persistence; + +namespace Optivem.Kata.Banking.Web.Extensions +{ + public static class IServiceCollectionExtensions + { + public static void Register(this IServiceCollection services, ConfigurationManager configuration) + { + // Add services to the container. + + services.AddControllers(); + + // TODO: VC: Move to Startup to enable re-use by tests + services.AddScoped(); + services.AddScoped(); + services.AddScoped(); + + services.AddDbContext(options => + { + options.UseSqlServer(configuration.GetConnectionString("BankingDatabase")); + }); + + services.AddMediatR(typeof(CoreModule)); + + // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle + services.AddEndpointsApiExplorer(); + services.AddSwaggerGen(); + } + } +} diff --git a/src/Optivem.Kata.Banking.Web/Program.cs b/src/Optivem.Kata.Banking.Web/Program.cs index efce207..42ac2c4 100644 --- a/src/Optivem.Kata.Banking.Web/Program.cs +++ b/src/Optivem.Kata.Banking.Web/Program.cs @@ -1,32 +1,8 @@ -using MediatR; -using Microsoft.EntityFrameworkCore; -using Optivem.Kata.Banking.Core; -using Optivem.Kata.Banking.Core.Domain.BankAccounts; -using Optivem.Kata.Banking.Core.Domain.Time; -using Optivem.Kata.Banking.Infrastructure; -using Optivem.Kata.Banking.Infrastructure.Persistence; +using Optivem.Kata.Banking.Web.Extensions; var builder = WebApplication.CreateBuilder(args); -// Add services to the container. - -builder.Services.AddControllers(); - -// TODO: VC: Move to Startup to enable re-use by tests -builder.Services.AddScoped(); -builder.Services.AddScoped(); -builder.Services.AddScoped(); - -builder.Services.AddDbContext(options => -{ - options.UseSqlServer(builder.Configuration.GetConnectionString("BankingDatabase")); -}); - -builder.Services.AddMediatR(typeof(CoreModule)); - -// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle -builder.Services.AddEndpointsApiExplorer(); -builder.Services.AddSwaggerGen(); +builder.Services.Register(builder.Configuration); var app = builder.Build();