Skip to content

Commit f5021aa

Browse files
author
raihanM95
committed
RepositoryWrapper implemented & ProductRepository initial
1 parent c353846 commit f5021aa

File tree

5 files changed

+61
-2
lines changed

5 files changed

+61
-2
lines changed

Application/IRepositoryWrapper.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using Application.Interfaces;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Text;
5+
6+
namespace Application
7+
{
8+
public interface IRepositoryWrapper
9+
{
10+
IProductRepository Product { get; }
11+
void Save();
12+
}
13+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using Application;
2+
using Application.Interfaces;
3+
using Infrastructure.Persistence.Contexts;
4+
using Infrastructure.Service.Repositories;
5+
using System;
6+
using System.Collections.Generic;
7+
using System.Text;
8+
9+
namespace Infrastructure.Service
10+
{
11+
public class RepositoryWrapper : IRepositoryWrapper
12+
{
13+
private RepositoryContext _repoContext;
14+
private IProductRepository _product;
15+
16+
public IProductRepository Product
17+
{
18+
get
19+
{
20+
if (_product == null)
21+
{
22+
_product = new ProductRepository(_repoContext);
23+
}
24+
return _product;
25+
}
26+
}
27+
28+
public RepositoryWrapper(RepositoryContext repositoryContext)
29+
{
30+
_repoContext = repositoryContext;
31+
}
32+
public void Save()
33+
{
34+
_repoContext.SaveChanges();
35+
}
36+
}
37+
}

Web/Extensions/ServiceExtensions.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using Infrastructure.Persistence.Contexts;
1+
using Application;
2+
using Infrastructure.Persistence.Contexts;
3+
using Infrastructure.Service;
24
using Microsoft.EntityFrameworkCore;
35
using Microsoft.Extensions.Configuration;
46
using Microsoft.Extensions.DependencyInjection;
@@ -17,6 +19,9 @@ public static void ConfigureSqlContext(this IServiceCollection services, IConfig
1719
services.AddDbContext<RepositoryContext>(option => option.UseSqlServer(connectionString));
1820
}
1921

20-
22+
public static void ConfigureRepositoryWrapper(this IServiceCollection services)
23+
{
24+
services.AddScoped<IRepositoryWrapper, RepositoryWrapper>();
25+
}
2126
}
2227
}

Web/Startup.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ public void ConfigureServices(IServiceCollection services)
2626
{
2727
services.AddControllersWithViews();
2828

29+
//Dependency Injection
2930
services.ConfigureSqlContext(Configuration);
31+
services.ConfigureRepositoryWrapper();
3032
}
3133

3234
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.

Web/Web.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
</ItemGroup>
1414

1515
<ItemGroup>
16+
<ProjectReference Include="..\Application\Application.csproj" />
1617
<ProjectReference Include="..\Infrastructure.Persistence\Infrastructure.Persistence.csproj" />
18+
<ProjectReference Include="..\Infrastructure.Service\Infrastructure.Service.csproj" />
1719
</ItemGroup>
1820

1921
</Project>

0 commit comments

Comments
 (0)