Skip to content

Commit 1d31d33

Browse files
committed
refactored layer
1 parent 75524e5 commit 1d31d33

21 files changed

+275
-301
lines changed

OnionArchitecture/OA.Infrastructure/Extension/ConfigureServiceContainer.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
using AutoMapper;
2-
using MediatR;
32
using Microsoft.EntityFrameworkCore;
43
using Microsoft.Extensions.Configuration;
54
using Microsoft.Extensions.DependencyInjection;
6-
using OA.Data;
75
using OA.Domain;
86
using OA.Infrastructure.Mapping;
9-
using OA.Persistence.Contract;
10-
using OA.Persistence.Repository;
7+
using OA.Persistence;
118
using OA.Service.Contract;
129
using OA.Service.Implementation;
1310
using System;
@@ -38,8 +35,6 @@ public static void AddAutoMapper(this IServiceCollection serviceCollection)
3835

3936
public static void AddAddScopedServices(this IServiceCollection serviceCollection)
4037
{
41-
serviceCollection.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));
42-
serviceCollection.AddScoped<ICustomerRepository, CustomerRepository>();
4338
serviceCollection.AddScoped<IApplicationDbContext>(provider => provider.GetService<ApplicationDbContext>());
4439
}
4540

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using OA.Domain.Entities;
3+
using System.Threading.Tasks;
4+
5+
namespace OA.Persistence
6+
{
7+
public class ApplicationDbContext : DbContext, IApplicationDbContext
8+
{
9+
// This constructor is used of runit testing
10+
public ApplicationDbContext()
11+
{
12+
13+
}
14+
public ApplicationDbContext(DbContextOptions options) : base(options)
15+
{
16+
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
17+
}
18+
19+
public DbSet<Customer> Customers { get; set; }
20+
public DbSet<Order> Orders { get; set; }
21+
public DbSet<Product> Products { get; set; }
22+
public DbSet<Category> Categories { get; set; }
23+
public DbSet<Supplier> Suppliers { get; set; }
24+
25+
protected override void OnModelCreating(ModelBuilder modelBuilder)
26+
{
27+
modelBuilder.Entity<OrderDetail>().HasKey(o => new { o.OrderId, o.ProductId });
28+
}
29+
30+
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
31+
{
32+
if (!optionsBuilder.IsConfigured)
33+
{
34+
optionsBuilder
35+
.UseSqlServer("DataSource=app.db");
36+
}
37+
38+
}
39+
40+
public async Task<int> SaveChangesAsync()
41+
{
42+
return await base.SaveChangesAsync();
43+
}
44+
}
45+
}

OnionArchitecture/OA.Persistence/ApplicationDbContext.dgml

Lines changed: 185 additions & 0 deletions
Large diffs are not rendered by default.

OnionArchitecture/OA.Persistence/Contract/ICustomerRepository.cs

Lines changed: 0 additions & 12 deletions
This file was deleted.

OnionArchitecture/OA.Persistence/Contract/IGenericRepository.cs

Lines changed: 0 additions & 14 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using Microsoft.EntityFrameworkCore;
2+
using OA.Domain.Entities;
3+
using System.Threading.Tasks;
4+
5+
namespace OA.Persistence
6+
{
7+
public interface IApplicationDbContext
8+
{
9+
DbSet<Category> Categories { get; set; }
10+
DbSet<Customer> Customers { get; set; }
11+
DbSet<Order> Orders { get; set; }
12+
DbSet<Product> Products { get; set; }
13+
DbSet<Supplier> Suppliers { get; set; }
14+
15+
Task<int> SaveChangesAsync();
16+
}
17+
}

OnionArchitecture/OA.Persistence/OA.Persistence.csproj

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@
55
</PropertyGroup>
66

77
<ItemGroup>
8-
<ProjectReference Include="..\OA.Data\OA.Data.csproj" />
8+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.5">
10+
<PrivateAssets>all</PrivateAssets>
11+
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
12+
</PackageReference>
13+
</ItemGroup>
14+
15+
<ItemGroup>
16+
<ProjectReference Include="..\OA.Domain\OA.Domain.csproj" />
917
</ItemGroup>
1018

1119
</Project>

OnionArchitecture/OA.Persistence/Repository/CustomerRepository.cs

Lines changed: 0 additions & 51 deletions
This file was deleted.

OnionArchitecture/OA.Persistence/Repository/GenericRepository.cs

Lines changed: 0 additions & 46 deletions
This file was deleted.

OnionArchitecture/OA.Service/DependencyInjection.cs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
using MediatR;
22
using Microsoft.Extensions.DependencyInjection;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
63
using System.Reflection;
7-
using System.Text;
8-
using System.Threading.Tasks;
94

105
namespace OA.Service
116
{
12-
public static class DependencyInjection
7+
public static class DependencyInjection
138
{
149
public static void AddMediatorCQRS(this IServiceCollection services)
1510
{

0 commit comments

Comments
 (0)