Skip to content

Commit ffe19a2

Browse files
committed
clean architecture applied
1 parent 254170f commit ffe19a2

16 files changed

+186
-64
lines changed

run-aspnetcore-microservices.sln

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Ordering", "Ordering", "{4E
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.API", "src\Ordering\Ordering.API\Ordering.API.csproj", "{F3721C94-7623-44FD-97F6-BFE699D466F4}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.Application", "src\Ordering\Ordering.Application\Ordering.Application.csproj", "{77C22EB5-5A4C-4132-97C4-888C2C65B277}"
27+
EndProject
28+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.Core", "src\Ordering\Ordering.Core\Ordering.Core.csproj", "{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1}"
29+
EndProject
30+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Ordering.Infrastructure", "src\Ordering\Ordering.Infrastructure\Ordering.Infrastructure.csproj", "{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC}"
31+
EndProject
2632
Global
2733
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2834
Debug|Any CPU = Debug|Any CPU
@@ -49,6 +55,18 @@ Global
4955
{F3721C94-7623-44FD-97F6-BFE699D466F4}.Debug|Any CPU.Build.0 = Debug|Any CPU
5056
{F3721C94-7623-44FD-97F6-BFE699D466F4}.Release|Any CPU.ActiveCfg = Release|Any CPU
5157
{F3721C94-7623-44FD-97F6-BFE699D466F4}.Release|Any CPU.Build.0 = Release|Any CPU
58+
{77C22EB5-5A4C-4132-97C4-888C2C65B277}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
59+
{77C22EB5-5A4C-4132-97C4-888C2C65B277}.Debug|Any CPU.Build.0 = Debug|Any CPU
60+
{77C22EB5-5A4C-4132-97C4-888C2C65B277}.Release|Any CPU.ActiveCfg = Release|Any CPU
61+
{77C22EB5-5A4C-4132-97C4-888C2C65B277}.Release|Any CPU.Build.0 = Release|Any CPU
62+
{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
63+
{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
64+
{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
65+
{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1}.Release|Any CPU.Build.0 = Release|Any CPU
66+
{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
67+
{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC}.Debug|Any CPU.Build.0 = Debug|Any CPU
68+
{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC}.Release|Any CPU.ActiveCfg = Release|Any CPU
69+
{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC}.Release|Any CPU.Build.0 = Release|Any CPU
5270
EndGlobalSection
5371
GlobalSection(SolutionProperties) = preSolution
5472
HideSolutionNode = FALSE
@@ -62,6 +80,9 @@ Global
6280
{2C6332B6-B5B3-429E-9A53-F3C257F3E4F2} = {16CE62A3-766F-4F03-900A-9661716AF7AE}
6381
{4E0CBAE4-FC9D-4CFA-9BBA-DF50B9EC48A1} = {1F32F974-1A66-4887-8DC2-A8BAB3AEE17D}
6482
{F3721C94-7623-44FD-97F6-BFE699D466F4} = {4E0CBAE4-FC9D-4CFA-9BBA-DF50B9EC48A1}
83+
{77C22EB5-5A4C-4132-97C4-888C2C65B277} = {4E0CBAE4-FC9D-4CFA-9BBA-DF50B9EC48A1}
84+
{006C8A82-B971-4AD6-8FD4-FF3CDE21E2A1} = {4E0CBAE4-FC9D-4CFA-9BBA-DF50B9EC48A1}
85+
{F8F12D19-E4C1-4018-A947-7FA81DFFD4BC} = {4E0CBAE4-FC9D-4CFA-9BBA-DF50B9EC48A1}
6586
EndGlobalSection
6687
GlobalSection(ExtensibilityGlobals) = postSolution
6788
SolutionGuid = {976E779A-BDC9-44B4-A778-269979171BDE}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading.Tasks;
5+
6+
namespace Ordering.API.Controllers
7+
{
8+
public class OrderController
9+
{
10+
}
11+
}

src/Ordering/Ordering.API/Controllers/WeatherForecastController.cs

Lines changed: 0 additions & 39 deletions
This file was deleted.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
using EventBusRabbitMQ.Events;
2+
using Microsoft.Extensions.Logging;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Threading.Tasks;
7+
8+
namespace Ordering.API.EventHandlers
9+
{
10+
public class BasketCheckoutEventHandler
11+
{
12+
private readonly IOrderService _orderService;
13+
private readonly ILogger<BasketCheckoutEventHandler> _logger;
14+
15+
public BasketCheckoutEventHandler(IOrderService orderService, ILogger<BasketCheckoutEventHandler> logger)
16+
{
17+
_orderService = orderService ?? throw new ArgumentNullException(nameof(orderService));
18+
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
19+
}
20+
21+
public async Task Handle(BasketCheckoutEvent @event)
22+
{
23+
//var order = _mapping order object
24+
//await _orderService.CheckOut(order);
25+
}
26+
}
27+
28+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using Microsoft.AspNetCore.Builder;
2+
using Microsoft.Extensions.DependencyInjection;
3+
using Microsoft.Extensions.Hosting;
4+
using Ordering.API.RabbitMQ;
5+
6+
namespace Ordering.API.Extentions
7+
{
8+
public static class ApplicationBuilderExtentions
9+
{
10+
public static EventBusRabbitMQConsumer Listener { get; set; }
11+
12+
public static IApplicationBuilder UseRabbitListener(this IApplicationBuilder app)
13+
{
14+
Listener = app.ApplicationServices.GetService<EventBusRabbitMQConsumer>();
15+
var life = app.ApplicationServices.GetService<IHostApplicationLifetime>();
16+
17+
life.ApplicationStarted.Register(OnStarted);
18+
life.ApplicationStopping.Register(OnStopping);
19+
20+
return app;
21+
}
22+
23+
private static void OnStarted()
24+
{
25+
Listener.Consume();
26+
}
27+
28+
private static void OnStopping()
29+
{
30+
Listener.Disconnect();
31+
}
32+
}
33+
}
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Web">
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
44
<TargetFramework>netcoreapp3.1</TargetFramework>
55
</PropertyGroup>
66

7+
<ItemGroup>
8+
<ProjectReference Include="..\..\Common\EventBusRabbitMQ\EventBusRabbitMQ.csproj" />
9+
</ItemGroup>
10+
711

812
</Project>

src/Common/EventBusRabbitMQ/Consumer/EventBusRabbitMQConsumer.cs renamed to src/Ordering/Ordering.API/RabbitMQ/EventBusRabbitMQConsumer.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1-
using EventBusRabbitMQ.Common;
1+
using EventBusRabbitMQ;
2+
using EventBusRabbitMQ.Common;
23
using EventBusRabbitMQ.Events;
34
using Newtonsoft.Json;
45
using RabbitMQ.Client;
56
using RabbitMQ.Client.Events;
67
using System;
78
using System.Text;
89

9-
namespace EventBusRabbitMQ.Consumer
10+
namespace Ordering.API.RabbitMQ
1011
{
1112
public class EventBusRabbitMQConsumer
1213
{

src/Ordering/Ordering.API/Startup.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.Linq;
4-
using System.Threading.Tasks;
1+
using EventBusRabbitMQ;
52
using Microsoft.AspNetCore.Builder;
63
using Microsoft.AspNetCore.Hosting;
7-
using Microsoft.AspNetCore.Mvc;
84
using Microsoft.Extensions.Configuration;
95
using Microsoft.Extensions.DependencyInjection;
106
using Microsoft.Extensions.Hosting;
11-
using Microsoft.Extensions.Logging;
7+
using Ordering.API.Extentions;
8+
using Ordering.API.RabbitMQ;
9+
using RabbitMQ.Client;
1210

1311
namespace Ordering.API
1412
{
@@ -25,6 +23,32 @@ public Startup(IConfiguration configuration)
2523
public void ConfigureServices(IServiceCollection services)
2624
{
2725
services.AddControllers();
26+
27+
#region RabbitMQ Dependencies
28+
29+
services.AddSingleton<IRabbitMQConnection>(sp =>
30+
{
31+
var factory = new ConnectionFactory()
32+
{
33+
HostName = Configuration["EventBus:HostName"]
34+
};
35+
36+
if (!string.IsNullOrEmpty(Configuration["EventBus:UserName"]))
37+
{
38+
factory.UserName = Configuration["EventBus:UserName"];
39+
}
40+
41+
if (!string.IsNullOrEmpty(Configuration["EventBus:Password"]))
42+
{
43+
factory.Password = Configuration["EventBus:Password"];
44+
}
45+
46+
return new RabbitMQConnection(factory);
47+
});
48+
49+
services.AddSingleton<EventBusRabbitMQConsumer>();
50+
51+
#endregion
2852
}
2953

3054
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
@@ -43,6 +67,9 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
4367
{
4468
endpoints.MapControllers();
4569
});
70+
71+
//Initilize Rabbit Listener in ApplicationBuilderExtentions
72+
app.UseRabbitListener();
4673
}
4774
}
4875
}

src/Ordering/Ordering.API/WeatherForecast.cs

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

src/Ordering/Ordering.API/appsettings.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,11 @@
66
"Microsoft.Hosting.Lifetime": "Information"
77
}
88
},
9-
"AllowedHosts": "*"
9+
"AllowedHosts": "*",
10+
11+
"EventBus": {
12+
"HostName": "localhost",
13+
"UserName": "guest",
14+
"Password": "guest"
15+
}
1016
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Ordering.Application
4+
{
5+
public class Class1
6+
{
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

src/Ordering/Ordering.Core/Class1.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Ordering.Core
4+
{
5+
public class Class1
6+
{
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
using System;
2+
3+
namespace Ordering.Infrastructure
4+
{
5+
public class Class1
6+
{
7+
}
8+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
5+
</PropertyGroup>
6+
7+
</Project>

0 commit comments

Comments
 (0)