Spliting projects

This commit is contained in:
Ivan Paulovich
2017-12-21 15:59:03 -02:00
parent ffdc36dbd2
commit fc74b10766
157 changed files with 419 additions and 545 deletions

BIN
Producer.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 113 KiB

131
README.md
View File

@@ -1,8 +1,10 @@
A solution for Blogging based on a Event-Driven architecture with DDD and CQRS. The full solution contains three applications. A solution for Blogging based on a Event-Driven architecture with DDD and CQRS. The full solution contains three applications.
* A Web API which receives Commands to produces Domain Events also receives Queries to return JSON. * A Producer Web API which receives Commands to produces Domain Events also receives Queries to return JSON.
* A Consumer App that reads the Event Stream and do a projection to a MongoDB database. * A Consumer Console App that reads the Event Stream and do a projection to a MongoDB database.
* A Web API for authentication and JWT generation. * A Web API for authentication and JWT generation.
[Blogging API Source Code on GitHub](https://github.com/ivanpaulovich/jambo)
#### Requirements #### Requirements
* [Visual Studio 2017 + Update 3](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes) * [Visual Studio 2017 + Update 3](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes)
* [.NET SDK 2.0](https://www.microsoft.com/net/download/core) * [.NET SDK 2.0](https://www.microsoft.com/net/download/core)
@@ -47,86 +49,75 @@ ba28cf144478 mongo "docker-entrypoint..." 2 days ago
If Kafka is running good it will be working with the `10.0.75.1:9092` connection string and if MongoDB is running good it will be working at `mongodb://10.0.75.1:27017`. If Kafka is running good it will be working with the `10.0.75.1:9092` connection string and if MongoDB is running good it will be working at `mongodb://10.0.75.1:27017`.
#### The Domain ## Running the applications
![Domain](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Domain.png)
#### As Aplicações desta Solução You have two options to run the three applications, one is by opening on Visual Studio 2017 and another is by dotnet core commands.
* **Producer**: Web API que recebe os comandos de edição de conteúdo, produz Eventos de Domínio e publica as mensagens em um tópico no Kafka.
* **Consumer**: Aplicativo Console que consome as mensagens do Kafka, deserializa em Eventos de Domínio e aplica nas agregações persistindo no MongoDB o novo estado.
* **Auth**: Web API que gera tokens de autenticação para acesso ao WebAPI.
#### Por onde começar? ### Option 1 - Running with Visual Studio 2017
Há duas formas de iniciar a solução.
##### 1. O jeito fácil Open the three solutions with three Visual Studio 2017 them run the following projects.
Resolver os [pré-requisitos](https://github.com/ivanpaulovich/jambo/#prerequisitos), definir o projeto inicial como sendo o `docker-compose` e então apertar `Ctrl+F5` para executar todas as aplicações. Se tudo estiver correto, digite `docker ps` no seu terminal para verificar em quais portas cada aplicação está executando. Será algo assim: * `Jambo.Auth.UI`
* `Jambo.Consumer.UI`
* `Jambo.Producer.UI`.
![Enviando comandos](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Docker-PS.PNG) ### Option 2 - Running with dotnet commands
A partir daí basta acessar: #### How to run the Bearer Authencation API
* Auth em http://localhost:32775/swagger/
* Producer em http://localhost:32776/swagger/
Leia o [o jeito não tão fácil](https://github.com/ivanpaulovich/jambo/#2-o-jeito-não-tão-fácil) para entender como criar um Token no Auth API para consumir os serviços do Producer API via swagger. 1. Run the command `dotnet run` at `source\Auth\Jambo.Auth.UI` folder.
```
$ dotnet run
Using launch settings from C:\git\jambo\source\Auth\Jambo.Auth.UI\Properties\launchSettings.json...
Hosting environment: Development
Content root path: C:\git\jambo\source\Auth\Jambo.Auth.UI
Now listening on: http://localhost:16024
Application started. Press Ctrl+C to shut down.
```
2. Navigate to the Swagger UI at (eg. http://localhost:16024/swagger).
3. Post the following credentials:
```
{
"username": "ivanpaulovich",
"password": "mysecret"
}
```
4. __Store the Bearer Token__ because you will need the token value later to log on Producer API.
```
{
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiJhYzA4MmE3OS1lMWY3LTQ4MTktYmU1Mi1hOTQwMTBkM2VjZTciLCJzdWIiOiJzdHJpbmciLCJleHAiOjE1MTI0Nzg5ODgsImlzcyI6Imh0dHA6Ly9teWFjY291bnRhcGkiLCJhdWQiOiJodHRwOi8vbXlhY2NvdW50YXBpIn0.9YKGmKaptLBDcExHhPOQ3_j9TsdbkcRf8ZtvIkdq8Go",
"expiration": "2017-12-05T13:03:08Z"
}
```
#### How to run the Consumer API
##### 2. O jeito não tão fácil 1. Run the command `dotnet run` at `source\Consumer\Jambo.Consumer.UI` folder
A outra opção é inicializar aplicação por aplicação, seguindo o seguintes passos: ```
$ dotnet run
11/5/2017 11:17:20 AM Waiting for events..
11/5/2017 11:18:20 AM Waiting for events..
11/5/2017 11:19:20 AM Waiting for events..
11/5/2017 11:20:20 AM Waiting for events..
11/5/2017 11:21:20 AM Waiting for events..
11/5/2017 11:22:20 AM Waiting for events..
```
1. Execute o projeto **Jambo.Auth.WebAPI** e chame o método *Account/Token* com qualquer usuário e senha. *Guarde este token*. 3. __Attention:__ keep the Console App running for events processing.
![Auth](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Auth.PNG) #### How to run the Producer API
![Auth com Token](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Auth1.PNG) ![Authorization](https://github.com/ivanpaulovich/jambo/blob/master/Producer.png)
3. Execute o projeto **Jambo.Producer.WebAPI** e clique no botão *Authorization* (topo direito da página). 1. Run the command `dotnet run` at the `source\Producer\Jambo.Producer.UI` folder.
Digite `bearer + valor_do_token` e clique em fechar. Algo assim: ```
![Autorizando](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Producer.PNG) $ dotnet run
Chame os métodos para manutenção dos dados do Blog, Posts e Comentários. Using launch settings from C:\git\jambo\source\Producer\Jambo.Producer.UI\Properties\launchSettings.json...
![Enviando comandos](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Producer02.PNG) Hosting environment: Development
Content root path: C:\git\jambo\source\Producer\Jambo.Producer.UI
Now listening on: http://localhost:16959
Application started. Press Ctrl+C to shut down.
```
2. Execute o projeto **Jambo.Consumer.Console** e garante que ele **contínua em execução**. 2. Navigate to the Swagger UI (eg. http://localhost:14398/swagger).
![Comsumer em execução](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Consumer.PNG)
4. Visualize suas modificações
![Queries](https://github.com/ivanpaulovich/jambo/blob/master/docs/images/Producer03.PNG)
#### Demo
* **Auth API**: http://jambo.westus.cloudapp.azure.com:7070/swagger/.
* **Producer**: http://jambo.westus.cloudapp.azure.com:7080/swagger/.
* **Consumer**: Executa em background neste servidor.
#### Próximos passos?
1. Publicar os containers no Azure.
2. Criar um CI/CD para atualizar os containers a cada commit.
3. Criar testes de unidade, testes automatizados.
4. Consumir serviços externos.
5. Implementação alternativa de barramento: Azure Event Hubs
6. Implementação alternativa de snapshot: Azure Cosmos DB
7. Implementar um HealthCheck
#### Pré-requisitos
* [Visual Studio 2017 + Update 3](https://www.visualstudio.com/en-us/news/releasenotes/vs2017-relnotes)
* [.NET SDK 2.0](https://www.microsoft.com/net/download/core)
* [Docker](https://docs.docker.com/docker-for-windows/install/) (Opcional)
* [Robomongo](https://robomongo.org/) (Opcional)
#### Agradecimentos
Obrigado aos amigos que me estimularam a criar este projeto e estão sempre contribuindo e dando feedback.
* [Vinicius Baldotto](https://github.com/Baldotto)
* [André Paulovich](https://github.com/andrepaulovich)
* André Mendes
Obrigado de verdade!
#### Deixe o seu feedback
Agradeço todo comentário sobre o projeto. Envie suas dúvidas e sugestões no [Fórum](https://github.com/ivanpaulovich/jambo/issues).
#### Histórico de Versões
* 10/set/2017:
[![release](https://img.shields.io/github/release/ivanpaulovich/nixy.svg?style=flat-square)](https://github.com/ivanpaulovich/jambo/releases/latest)

View File

@@ -1,54 +0,0 @@
version: '2'
services:
jambo.auth.webapi:
image: ivanpaulovich/jambo:auth.webapi
links:
- "mongodb:mongo"
depends_on:
- mongodb
ports:
- 7070:80
jambo.producer.webapi:
image: ivanpaulovich/jambo:producer.webapi
ports:
- 7080:80
links:
- "mongodb:mongo"
depends_on:
- mongodb
- kafka
environment:
- ASPNETCORE_URLS=http://*:80
- ServiceBus__ConnectionString=kafka:9092
- ServiceBus__Topic=jambov32
- MongoDB__ConnectionString=mongodb://mongodb:27017
- MongoDB__Database=jambov32
jambo.consumer.console:
image: ivanpaulovich/jambo:consumer.console
links:
- "mongodb:mongo"
depends_on:
- mongodb
- kafka
environment:
- ASPNETCORE_URLS=http://*:80
- ServiceBus__ConnectionString=kafka:9092
- ServiceBus__Topic=jambov32
- MongoDB__ConnectionString=mongodb://mongodb:27017
- MongoDB__Database=jambov32
mongodb:
image: mongo
container_name: "mongodb"
ports:
- 27017:27017
kafka:
image: landoop/fast-data-dev:latest
ports:
- 2181:2181
- 3030:3030
- 8081-8083:8081-8083
- 9581-9585:9581-9585
- 9092:9092
environment:
- ADV_HOST=kafka

View File

@@ -1 +0,0 @@
theme: jekyll-theme-cayman

Binary file not shown.

Before

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 38 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 44 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 53 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 39 KiB

View File

@@ -6,9 +6,10 @@ services:
ports: ports:
- 27017:27017 - 27017:27017
kafka: kafka:
image: landoop/fast-data-dev:latest image: spotify/kafka
ports: ports:
- 3030:3030 - 2181:2181
- 9092:9092 - 9092:9092
environment: environment:
- ADV_HOST=10.0.75.1 - ADVERTISED_HOST=10.0.75.1
- ADVERTISED_PORT=9092

View File

@@ -0,0 +1,17 @@
namespace Jambo.Auth.Application.Commands
{
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
[DataContract]
public class LoginCommand
{
[Required]
[DataMember]
public string Username { get; set; }
[Required]
[DataMember]
public string Password { get; set; }
}
}

View File

@@ -4,12 +4,6 @@
<TargetFramework>netstandard2.0</TargetFramework> <TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<Compile Remove="CommandHandlers\**" />
<EmbeddedResource Remove="CommandHandlers\**" />
<None Remove="CommandHandlers\**" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Mediatr" Version="3.0.1" /> <PackageReference Include="Mediatr" Version="3.0.1" />
<PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0" /> <PackageReference Include="System.ComponentModel.Annotations" Version="4.4.0" />

View File

@@ -0,0 +1,15 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;NU1701;CS1591</NoWarn>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Jambo.Auth.Application\Jambo.Auth.Application.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,17 +1,15 @@
using System; namespace Jambo.Auth.UI
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
using System.Text;
using Jambo.Auth.Application.Commands;
namespace Jambo.Auth.UI
{ {
using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Authorization;
using System.IdentityModel.Tokens.Jwt;
using Microsoft.IdentityModel.Tokens;
using System.Security.Claims;
using System.Text;
using Jambo.Auth.Application.Commands;
[Route("api/[controller]")] [Route("api/[controller]")]
public class AccountController : Controller public class AccountController : Controller
{ {
@@ -46,7 +44,7 @@ namespace Jambo.Auth.UI
config.Issuer, config.Issuer,
config.Issuer, config.Issuer,
GetTokenClaims(user), GetTokenClaims(user),
expires: DateTime.UtcNow.AddDays(1), expires: DateTime.UtcNow.AddDays(7),
signingCredentials: new SigningCredentials( signingCredentials: new SigningCredentials(
new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.SecretKey)), new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config.SecretKey)),
SecurityAlgorithms.HmacSha256) SecurityAlgorithms.HmacSha256)
@@ -57,9 +55,8 @@ namespace Jambo.Auth.UI
{ {
return new List<Claim> return new List<Claim>
{ {
new Claim(JwtRegisteredClaimNames.Jti, user.UserId.ToString()), new Claim(JwtRegisteredClaimNames.Jti, user.Username),
new Claim(JwtRegisteredClaimNames.Sub, user.UserId.ToString()), new Claim(JwtRegisteredClaimNames.Sub, user.Password),
new Claim(ClaimTypes.GroupSid, user.SchoolId.ToString()),
}; };
} }
} }

View File

@@ -3,4 +3,4 @@ ARG source
WORKDIR /app WORKDIR /app
EXPOSE 80 EXPOSE 80
COPY ${source:-obj/Docker/publish} . COPY ${source:-obj/Docker/publish} .
ENTRYPOINT ["dotnet", "Jambo.Auth.Infrastructure.dll"] ENTRYPOINT ["dotnet", "Jambo.Auth.UI.dll"]

View File

@@ -4,6 +4,16 @@
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<NoWarn>1701;1702;1705;NU1701</NoWarn>
<DocumentationFile>bin\Debug\netcoreapp2.0\Jambo.Auth.UI.xml</DocumentationFile>
</PropertyGroup>
<ItemGroup>
<None Include="appsettings.Development.json" />
<None Include="appsettings.json" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" /> <PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
@@ -11,7 +21,6 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Auth.Application\Jambo.Auth.Application.csproj" /> <ProjectReference Include="..\Jambo.Auth.Application\Jambo.Auth.Application.csproj" />
<ProjectReference Include="..\Jambo.Auth.UI\Jambo.Auth.UI.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,15 +1,8 @@
using System; namespace Jambo.Auth.UI
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
namespace Jambo.Auth.Infrastructure
{ {
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
public class Program public class Program
{ {
public static void Main(string[] args) public static void Main(string[] args)

View File

@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:16023/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Jambo.Auth.UI": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:16024/"
}
}
}

View File

@@ -1,10 +1,10 @@
using Microsoft.AspNetCore.Builder; namespace Jambo.Auth.UI
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
namespace Jambo.Auth.Infrastructure
{ {
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
public class Startup public class Startup
{ {
public Startup(IConfiguration configuration) public Startup(IConfiguration configuration)

View File

@@ -12,7 +12,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" /> <ProjectReference Include="..\..\Shared\Jambo.Domain\Jambo.Domain.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -1,11 +1,11 @@
using Jambo.Domain.Model; namespace Jambo.Consumer.Infrastructure.DataAccess
using Jambo.Domain.Model.Blogs;
using Jambo.Domain.Model.Posts;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
namespace Jambo.Consumer.Infrastructure.DataAccess
{ {
using Jambo.Domain.Model;
using Jambo.Domain.Model.Blogs;
using Jambo.Domain.Model.Posts;
using MongoDB.Bson.Serialization;
using MongoDB.Driver;
public class MongoContext public class MongoContext
{ {
private readonly MongoClient mongoClient; private readonly MongoClient mongoClient;

View File

@@ -1,12 +1,11 @@
using Jambo.Domain.Model.Blogs; namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs
using Jambo.Domain.Model.Posts;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs
{ {
using Jambo.Domain.Model.Blogs;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class BlogReadOnlyRepository : IBlogReadOnlyRepository public class BlogReadOnlyRepository : IBlogReadOnlyRepository
{ {
private readonly MongoContext _mongoContext; private readonly MongoContext _mongoContext;

View File

@@ -1,10 +1,10 @@
using Jambo.Domain.Model.Blogs; namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs
using MongoDB.Driver;
using System;
using System.Threading.Tasks;
namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs
{ {
using Jambo.Domain.Model.Blogs;
using MongoDB.Driver;
using System;
using System.Threading.Tasks;
public class BlogWriteOnlyRepository : IBlogWriteOnlyRepository public class BlogWriteOnlyRepository : IBlogWriteOnlyRepository
{ {
private readonly MongoContext mongoContext; private readonly MongoContext mongoContext;

View File

@@ -1,12 +1,11 @@
using Jambo.Domain.Model.Blogs; namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts
using Jambo.Domain.Model.Posts;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts
{ {
using Jambo.Domain.Model.Posts;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
public class PostReadOnlyRepository : IPostReadOnlyRepository public class PostReadOnlyRepository : IPostReadOnlyRepository
{ {
private readonly MongoContext _mongoContext; private readonly MongoContext _mongoContext;

View File

@@ -1,11 +1,10 @@
using Jambo.Domain.Model.Blogs; namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts
using Jambo.Domain.Model.Posts;
using MongoDB.Driver;
using System;
using System.Threading.Tasks;
namespace Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts
{ {
using Jambo.Domain.Model.Posts;
using MongoDB.Driver;
using System;
using System.Threading.Tasks;
public class PostWriteOnlyRepository : IPostWriteOnlyRepository public class PostWriteOnlyRepository : IPostWriteOnlyRepository
{ {
private readonly MongoContext _mongoContext; private readonly MongoContext _mongoContext;

View File

@@ -27,11 +27,7 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Consumer.Application\Jambo.Consumer.Application.csproj" /> <ProjectReference Include="..\Jambo.Consumer.Application\Jambo.Consumer.Application.csproj" />
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" /> <ProjectReference Include="..\..\Shared\Jambo.Domain\Jambo.Domain.csproj" />
</ItemGroup> </ItemGroup>
<Target Name="CopyFiles" AfterTargets="build">
<Copy DestinationFolder="..\Jambo.Consumer.UI\bin\Debug\netcoreapp2.0" SourceFiles="$(OutputPath)\Jambo.Consumer.Infrastructure.dll" SkipUnchangedFiles="false" />
<Copy DestinationFolder="..\Jambo.Consumer.UI\bin\Debug\netcoreapp2.0" SourceFiles="$(OutputPath)\Jambo.Consumer.Infrastructure.pdb" SkipUnchangedFiles="false" />
</Target>
</Project> </Project>

View File

@@ -0,0 +1,38 @@
namespace Jambo.Consumer.Infrastructure.Modules
{
using Autofac;
using Autofac.Features.Variance;
using Jambo.Consumer.Application.DomainEventHandlers.Blogs;
using MediatR;
using System.Collections.Generic;
using System.Reflection;
public class MediatRModule : Autofac.Module
{
protected override void Load(ContainerBuilder builder)
{
builder.RegisterSource(new ContravariantRegistrationSource());
builder
.RegisterType<Mediator>()
.As<IMediator>()
.InstancePerLifetimeScope();
builder
.Register<SingleInstanceFactory>(ctx => {
var c = ctx.Resolve<IComponentContext>();
return t => { object o; return c.TryResolve(t, out o) ? o : null; };
})
.InstancePerLifetimeScope();
builder
.Register<MultiInstanceFactory>(ctx => {
var c = ctx.Resolve<IComponentContext>();
return t => (IEnumerable<object>)c.Resolve(typeof(IEnumerable<>).MakeGenericType(t));
})
.InstancePerLifetimeScope();
builder.RegisterAssemblyTypes(typeof(BlogCreatedEventHandler).GetTypeInfo().Assembly).AsImplementedInterfaces(); // via assembly scan
}
}
}

View File

@@ -1,17 +1,17 @@
using Confluent.Kafka; namespace Jambo.Consumer.Infrastructure.ServiceBus
using Confluent.Kafka.Serialization;
using Jambo.Domain.Exceptions;
using Jambo.Domain.Model;
using Jambo.Domain.ServiceBus;
using MediatR;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace Jambo.Consumer.Infrastructure.ServiceBus
{ {
using Confluent.Kafka;
using Confluent.Kafka.Serialization;
using Jambo.Domain.Exceptions;
using Jambo.Domain.Model;
using Jambo.Domain.ServiceBus;
using MediatR;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
public class Bus : ISubscriber public class Bus : ISubscriber
{ {
public readonly string brokerList; public readonly string brokerList;

View File

@@ -28,7 +28,8 @@
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Consumer.Application\Jambo.Consumer.Application.csproj" /> <ProjectReference Include="..\Jambo.Consumer.Application\Jambo.Consumer.Application.csproj" />
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" /> <ProjectReference Include="..\..\Shared\Jambo.Domain\Jambo.Domain.csproj" />
<ProjectReference Include="..\Jambo.Consumer.Infrastructure\Jambo.Consumer.Infrastructure.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -29,10 +29,6 @@
public IServiceProvider ConfigureServices(IServiceCollection services) public IServiceProvider ConfigureServices(IServiceCollection services)
{ {
LoadInfrastructureAssemblies();
services.AddMediatR(typeof(BlogCreatedEventHandler).GetTypeInfo().Assembly);
ContainerBuilder builder = new ContainerBuilder(); ContainerBuilder builder = new ContainerBuilder();
builder.Populate(services); builder.Populate(services);
builder.RegisterModule(new ConfigurationModule(Configuration)); builder.RegisterModule(new ConfigurationModule(Configuration));
@@ -42,16 +38,6 @@
return serviceProvider; return serviceProvider;
} }
private void LoadInfrastructureAssemblies()
{
string[] fileNames = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll", SearchOption.TopDirectoryOnly)
.Where(filePath => Path.GetFileName(filePath).StartsWith("Jambo.Consumer.Infrastructure", StringComparison.OrdinalIgnoreCase))
.ToArray();
foreach (string file in fileNames)
AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
}
public void Run() public void Run()
{ {
IMediator mediator = serviceProvider.GetService<IMediator>(); IMediator mediator = serviceProvider.GetService<IMediator>();

View File

@@ -14,6 +14,11 @@
"BrokerList": "10.0.75.1:9092", "BrokerList": "10.0.75.1:9092",
"Topic": "jambov32" "Topic": "jambov32"
} }
},
{
"type": "Jambo.Consumer.Infrastructure.Modules.MediatRModule",
"properties": {
}
} }
] ]
} }

View File

@@ -3,15 +3,15 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26730.3 VisualStudioVersion = 15.0.26730.3
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Domain", "Jambo.Domain\Jambo.Domain.csproj", "{ED9F252F-10E5-4A65-ADA0-122D61D655A4}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.Application", "Jambo.Consumer.Application\Jambo.Consumer.Application.csproj", "{601F90B1-4BE4-462E-8595-AAAA49B80405}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.Application", "Jambo.Consumer.Application\Jambo.Consumer.Application.csproj", "{601F90B1-4BE4-462E-8595-AAAA49B80405}"
EndProject EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Domain.UnitTests", "Jambo.Domain.UnitTests\Jambo.Domain.UnitTests.csproj", "{B59AD81D-93F9-425F-8F87-DF13561BE424}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.Infrastructure", "Jambo.Consumer.Infrastructure\Jambo.Consumer.Infrastructure.csproj", "{645C9138-DA59-48C8-A15E-D720874DD148}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.Infrastructure", "Jambo.Consumer.Infrastructure\Jambo.Consumer.Infrastructure.csproj", "{645C9138-DA59-48C8-A15E-D720874DD148}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jambo.Consumer.UI", "Jambo.Consumer.UI\Jambo.Consumer.UI.csproj", "{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}" Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.UI", "Jambo.Consumer.UI\Jambo.Consumer.UI.csproj", "{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Domain", "..\Shared\Jambo.Domain\Jambo.Domain.csproj", "{B0475864-44AC-4A6A-9970-CC5EEA01C2CF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Domain.UnitTests", "..\Shared\Jambo.Domain.UnitTests\Jambo.Domain.UnitTests.csproj", "{04732413-3F55-4194-B406-2F84666B1F6C}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -19,18 +19,10 @@ Global
Release|Any CPU = Release|Any CPU Release|Any CPU = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution GlobalSection(ProjectConfigurationPlatforms) = postSolution
{ED9F252F-10E5-4A65-ADA0-122D61D655A4}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ED9F252F-10E5-4A65-ADA0-122D61D655A4}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ED9F252F-10E5-4A65-ADA0-122D61D655A4}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ED9F252F-10E5-4A65-ADA0-122D61D655A4}.Release|Any CPU.Build.0 = Release|Any CPU
{601F90B1-4BE4-462E-8595-AAAA49B80405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {601F90B1-4BE4-462E-8595-AAAA49B80405}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{601F90B1-4BE4-462E-8595-AAAA49B80405}.Debug|Any CPU.Build.0 = Debug|Any CPU {601F90B1-4BE4-462E-8595-AAAA49B80405}.Debug|Any CPU.Build.0 = Debug|Any CPU
{601F90B1-4BE4-462E-8595-AAAA49B80405}.Release|Any CPU.ActiveCfg = Release|Any CPU {601F90B1-4BE4-462E-8595-AAAA49B80405}.Release|Any CPU.ActiveCfg = Release|Any CPU
{601F90B1-4BE4-462E-8595-AAAA49B80405}.Release|Any CPU.Build.0 = Release|Any CPU {601F90B1-4BE4-462E-8595-AAAA49B80405}.Release|Any CPU.Build.0 = Release|Any CPU
{B59AD81D-93F9-425F-8F87-DF13561BE424}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B59AD81D-93F9-425F-8F87-DF13561BE424}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B59AD81D-93F9-425F-8F87-DF13561BE424}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B59AD81D-93F9-425F-8F87-DF13561BE424}.Release|Any CPU.Build.0 = Release|Any CPU
{645C9138-DA59-48C8-A15E-D720874DD148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {645C9138-DA59-48C8-A15E-D720874DD148}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{645C9138-DA59-48C8-A15E-D720874DD148}.Debug|Any CPU.Build.0 = Debug|Any CPU {645C9138-DA59-48C8-A15E-D720874DD148}.Debug|Any CPU.Build.0 = Debug|Any CPU
{645C9138-DA59-48C8-A15E-D720874DD148}.Release|Any CPU.ActiveCfg = Release|Any CPU {645C9138-DA59-48C8-A15E-D720874DD148}.Release|Any CPU.ActiveCfg = Release|Any CPU
@@ -39,6 +31,14 @@ Global
{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Release|Any CPU.Build.0 = Release|Any CPU {E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Release|Any CPU.Build.0 = Release|Any CPU
{B0475864-44AC-4A6A-9970-CC5EEA01C2CF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B0475864-44AC-4A6A-9970-CC5EEA01C2CF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B0475864-44AC-4A6A-9970-CC5EEA01C2CF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B0475864-44AC-4A6A-9970-CC5EEA01C2CF}.Release|Any CPU.Build.0 = Release|Any CPU
{04732413-3F55-4194-B406-2F84666B1F6C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{04732413-3F55-4194-B406-2F84666B1F6C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{04732413-3F55-4194-B406-2F84666B1F6C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{04732413-3F55-4194-B406-2F84666B1F6C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View File

@@ -1,26 +0,0 @@
using MediatR;
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Runtime.Serialization;
using System.Text;
namespace Jambo.Auth.Application.Commands
{
[DataContract]
public class LoginCommand : IRequest
{
[Required]
[DataMember]
public Guid UserId { get; private set; }
[Required]
[DataMember]
public Guid SchoolId { get; private set; }
public LoginCommand()
{
}
}
}

View File

@@ -1,16 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Jambo.Auth.Application\Jambo.Auth.Application.csproj" />
</ItemGroup>
</Project>

View File

@@ -1,24 +0,0 @@
namespace Jambo.Consumer.Infrastructure
{
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System.IO;
class Program
{
public static void Main(string[] args)
{
var builder = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.AddEnvironmentVariables();
IConfigurationRoot configuration = builder.Build();
IServiceCollection serviceCollection = new ServiceCollection();
Startup startup = new Startup(configuration);
startup.ConfigureServices(serviceCollection);
startup.Run();
}
}
}

View File

@@ -1,59 +0,0 @@
using Autofac;
using Autofac.Extensions.DependencyInjection;
using Jambo.Consumer.Application.DomainEventHandlers.Blogs;
using Jambo.Consumer.Infrastructure.Modules;
using Jambo.Domain.ServiceBus;
using MediatR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Reflection;
using System.Threading;
namespace Jambo.Consumer.Infrastructure
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
IServiceProvider serviceProvider;
public IServiceProvider ConfigureServices(IServiceCollection services)
{
services.AddMediatR(typeof(BlogCreatedEventHandler).GetTypeInfo().Assembly);
ContainerBuilder container = new ContainerBuilder();
container.Populate(services);
container.RegisterModule(new ApplicationModule(
Configuration.GetSection("MongoDB").GetValue<string>("ConnectionString"),
Configuration.GetSection("MongoDB").GetValue<string>("Database")));
container.RegisterModule(new BusModule(
Configuration.GetSection("ServiceBus").GetValue<string>("ConnectionString"),
Configuration.GetSection("ServiceBus").GetValue<string>("Topic")));
serviceProvider = new AutofacServiceProvider(container.Build());
return serviceProvider;
}
public void Run()
{
IMediator mediator = serviceProvider.GetService<IMediator>();
ISubscriber subscriber = serviceProvider.GetService<ISubscriber>();
subscriber.Listen(mediator);
while (true)
{
Thread.Sleep(1000 * 60);
}
}
}
}

View File

@@ -1,30 +0,0 @@
using System;
namespace Jambo.Domain.Model.Posts.Events
{
public class PostCreatedDomainEvent : DomainEvent
{
public Guid BlogId { get; private set; }
public int BlogVersion { get; private set; }
public PostCreatedDomainEvent(Guid aggregateRootId, int version,
DateTime createdDate, Header header, Guid blogId, int blogVersion)
: base(aggregateRootId, version, createdDate, header)
{
BlogId = blogId;
BlogVersion = blogVersion;
}
public static PostCreatedDomainEvent Create(AggregateRoot aggregateRoot,
Guid blogId, int blogVersion)
{
if (aggregateRoot == null)
throw new ArgumentNullException("aggregateRoot");
PostCreatedDomainEvent domainEvent = new PostCreatedDomainEvent(
aggregateRoot.Id, aggregateRoot.Version, DateTime.UtcNow, null, blogId, blogVersion);
return domainEvent;
}
}
}

View File

@@ -9,7 +9,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" /> <ProjectReference Include="..\..\Shared\Jambo.Domain\Jambo.Domain.csproj" />
</ItemGroup> </ItemGroup>
</Project> </Project>

View File

@@ -19,7 +19,7 @@
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" /> <ProjectReference Include="..\..\Shared\Jambo.Domain\Jambo.Domain.csproj" />
<ProjectReference Include="..\Jambo.Producer.Application\Jambo.Producer.Application.csproj" /> <ProjectReference Include="..\Jambo.Producer.Application\Jambo.Producer.Application.csproj" />
</ItemGroup> </ItemGroup>

Some files were not shown because too many files have changed in this diff Show More