Skip to content

Commit 75524e5

Browse files
authored
Merge pull request #15 from Amitpnk/feature/CQRS
Feature/cqrs
2 parents e0ef262 + 1e42021 commit 75524e5

29 files changed

+288
-236
lines changed

OnionArchitecture/.template.config/template.vstemplate

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<Name>Onion Architecture</Name>
55
<Description>WhiteApp or QuickApp API solution template which is built on Onion Architecture using .NET Core</Description>
66
<TemplateID>OnionArchitecture.CSharp</TemplateID>
7-
<DefaultName>OA</DefaultName>
7+
<DefaultName>OnionArchitecture</DefaultName>
88

99
<Icon>project-icon.png</Icon>
1010

OnionArchitecture/OA.Data/ApplicationContext.cs renamed to OnionArchitecture/OA.Data/ApplicationDbContext.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44

55
namespace OA.Data
66
{
7-
public class ApplicationContext : DbContext, IApplicationContext
7+
public class ApplicationDbContext : DbContext, IApplicationDbContext
88
{
99
// This constructor is used of runit testing
10-
public ApplicationContext()
10+
public ApplicationDbContext()
1111
{
1212

1313
}
14-
public ApplicationContext(DbContextOptions options) : base(options)
14+
public ApplicationDbContext(DbContextOptions options) : base(options)
1515
{
1616
ChangeTracker.QueryTrackingBehavior = QueryTrackingBehavior.NoTracking;
1717
}

OnionArchitecture/OA.Data/IApplicationContext.cs renamed to OnionArchitecture/OA.Data/IApplicationDbContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace OA.Data
66
{
7-
public interface IApplicationContext
7+
public interface IApplicationDbContext
88
{
99
DbSet<Category> Categories { get; set; }
1010
DbSet<Customer> Customers { get; set; }

OnionArchitecture/OA.Data/Migrations/20200627044955_Initial-setup.Designer.cs

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

OnionArchitecture/OA.Data/Migrations/CustomerContextModelSnapshot.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
namespace OA.Data.Migrations
1010
{
11-
[DbContext(typeof(ApplicationContext))]
11+
[DbContext(typeof(ApplicationDbContext))]
1212
partial class CustomerContextModelSnapshot : ModelSnapshot
1313
{
1414
protected override void BuildModel(ModelBuilder modelBuilder)

OnionArchitecture/OA.Infrastructure/Extension/ConfigureContainer.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.Logging;
23
using OA.Infrastructure.Middleware;
4+
using Serilog;
35

46
namespace OA.Infrastructure.Extension
57
{
@@ -21,5 +23,10 @@ public static void ConfigureSwagger(this IApplicationBuilder app)
2123
});
2224
}
2325

26+
public static void ConfigureSwagger(this ILoggerFactory loggerFactory)
27+
{
28+
loggerFactory.AddSerilog();
29+
}
30+
2431
}
2532
}

OnionArchitecture/OA.Infrastructure/Extension/ConfigureServiceContainer.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using AutoMapper;
2+
using MediatR;
23
using Microsoft.EntityFrameworkCore;
34
using Microsoft.Extensions.Configuration;
45
using Microsoft.Extensions.DependencyInjection;
@@ -12,7 +13,6 @@
1213
using System;
1314
using System.IO;
1415
using System.Reflection;
15-
using Microsoft.AspNetCore.Mvc.NewtonsoftJson;
1616

1717
namespace OA.Infrastructure.Extension
1818
{
@@ -21,7 +21,7 @@ public static class ConfigureServiceContainer
2121
public static void AddDbContext(this IServiceCollection serviceCollection,
2222
IConfiguration configuration, IConfigurationRoot configRoot)
2323
{
24-
serviceCollection.AddDbContext<ApplicationContext>(options =>
24+
serviceCollection.AddDbContext<ApplicationDbContext>(options =>
2525
options.UseSqlServer(configuration.GetConnectionString("OnionArchConn") ?? configRoot["ConnectionStrings:OnionArchConn"])
2626
);
2727
}
@@ -36,15 +36,15 @@ public static void AddAutoMapper(this IServiceCollection serviceCollection)
3636
serviceCollection.AddSingleton(mapper);
3737
}
3838

39-
public static void AddRepository(this IServiceCollection serviceCollection)
39+
public static void AddAddScopedServices(this IServiceCollection serviceCollection)
4040
{
4141
serviceCollection.AddScoped(typeof(IGenericRepository<>), typeof(GenericRepository<>));
4242
serviceCollection.AddScoped<ICustomerRepository, CustomerRepository>();
43+
serviceCollection.AddScoped<IApplicationDbContext>(provider => provider.GetService<ApplicationDbContext>());
4344
}
4445

4546
public static void AddTransientServices(this IServiceCollection serviceCollection)
4647
{
47-
serviceCollection.AddTransient<ICustomerService, CustomerService>();
4848
serviceCollection.AddTransient<IMailService, MailService>();
4949
}
5050

@@ -90,5 +90,11 @@ public static void AddController(this IServiceCollection serviceCollection)
9090
serviceCollection.AddControllers().AddNewtonsoftJson();
9191
}
9292

93+
//public static void AddMediatorCQRS(this IServiceCollection services)
94+
//{
95+
// //var assembly = AppDomain.CurrentDomain.Load("OA.Service");
96+
// services.AddMediatR(Assembly.GetExecutingAssembly());
97+
//}
98+
9399
}
94100
}

OnionArchitecture/OA.Persistence/Repository/CustomerRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ namespace OA.Persistence.Repository
1010
{
1111
public class CustomerRepository : ICustomerRepository
1212
{
13-
private readonly ApplicationContext _context;
14-
public CustomerRepository(ApplicationContext context)
13+
private readonly ApplicationDbContext _context;
14+
public CustomerRepository(ApplicationDbContext context)
1515
{
1616
_context = context;
1717
}

OnionArchitecture/OA.Persistence/Repository/GenericRepository.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ namespace OA.Persistence.Repository
99
public class GenericRepository<T> : IGenericRepository<T> where T : class
1010
{
1111
private readonly DbSet<T> entities;
12-
private readonly ApplicationContext _context;
12+
private readonly ApplicationDbContext _context;
1313

14-
public GenericRepository(ApplicationContext context)
14+
public GenericRepository(ApplicationDbContext context)
1515
{
1616
_context = context;
1717
entities = _context.Set<T>();

OnionArchitecture/OA.Service/Contract/ICustomerService.cs

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

0 commit comments

Comments
 (0)