Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
valentinajemuovic committed Jun 18, 2022
1 parent 86982ff commit c69d193
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -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<IAccountNumberGenerator, AccountNumberGenerator>();
services.AddScoped<IDateTimeService, DateTimeService>();
services.AddScoped<IBankAccountRepository, BankAccountRepository>();

services.AddDbContext<DatabaseContext>(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();
}
}
}
28 changes: 2 additions & 26 deletions src/Optivem.Kata.Banking.Web/Program.cs
Original file line number Diff line number Diff line change
@@ -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<IAccountNumberGenerator, AccountNumberGenerator>();
builder.Services.AddScoped<IDateTimeService, DateTimeService>();
builder.Services.AddScoped<IBankAccountRepository, BankAccountRepository>();

builder.Services.AddDbContext<DatabaseContext>(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();

Expand Down

0 comments on commit c69d193

Please sign in to comment.