@@ -1,8 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@@ -11,6 +10,7 @@
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.6.0" />
|
||||
<PackageReference Include="Autofac.Configuration" Version="4.0.1" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.0" />
|
||||
<PackageReference Include="MediatR" Version="3.0.1" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="2.0.0" />
|
||||
@@ -23,7 +23,6 @@
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<PackageReference Include="Confluent.Kafka" Version="0.11.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
@@ -31,8 +30,8 @@
|
||||
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</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>
|
||||
|
||||
@@ -1,29 +1,21 @@
|
||||
using Autofac;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Consumer.Infrastructure;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess.Repositories;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess;
|
||||
|
||||
namespace Jambo.Consumer.Infrastructure.Modules
|
||||
namespace Jambo.Consumer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess.Repositories.Blogs;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess.Repositories.Posts;
|
||||
using Jambo.Consumer.Infrastructure.DataAccess;
|
||||
|
||||
public class ApplicationModule : Module
|
||||
{
|
||||
public readonly string connectionString;
|
||||
public readonly string database;
|
||||
|
||||
public ApplicationModule(string connectionString, string database)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
this.database = database;
|
||||
}
|
||||
public string ConnectionString { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
MongoContext mongoContext = new MongoContext(connectionString, database);
|
||||
mongoContext.DatabaseReset(database);
|
||||
MongoContext mongoContext = new MongoContext(ConnectionString, DatabaseName);
|
||||
mongoContext.DatabaseReset(DatabaseName);
|
||||
|
||||
builder.Register(c => mongoContext)
|
||||
.As<MongoContext>().SingleInstance();
|
||||
|
||||
@@ -1,27 +1,20 @@
|
||||
using Autofac;
|
||||
using Jambo.Consumer.Infrastructure.ServiceBus;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using MediatR;
|
||||
|
||||
namespace Jambo.Consumer.Infrastructure.Modules
|
||||
namespace Jambo.Consumer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Jambo.Consumer.Infrastructure.ServiceBus;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
|
||||
public class BusModule : Module
|
||||
{
|
||||
private readonly string brokerList;
|
||||
private readonly string topic;
|
||||
|
||||
public BusModule(string brokerList, string topic)
|
||||
{
|
||||
this.brokerList = brokerList;
|
||||
this.topic = topic;
|
||||
}
|
||||
public string BrokerList { get; set; }
|
||||
public string Topic { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<Bus>()
|
||||
.As<ISubscriber>()
|
||||
.WithParameter("brokerList", brokerList)
|
||||
.WithParameter("topic", topic)
|
||||
.WithParameter("brokerList", BrokerList)
|
||||
.WithParameter("topic", Topic)
|
||||
.SingleInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
|
||||
namespace Jambo.Consumer.Infrastructure
|
||||
namespace Jambo.Consumer.Infrastructure
|
||||
{
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
|
||||
class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
{
|
||||
"MongoDB": {
|
||||
"ConnectionString": "mongodb://10.0.75.1:27017",
|
||||
"Database": "jambov32"
|
||||
},
|
||||
|
||||
"ServiceBus": {
|
||||
"ConnectionString": "10.0.75.1:9092",
|
||||
"Topic": "jambov32"
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,4 @@ ARG source
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
COPY ${source:-obj/Docker/publish} .
|
||||
ENTRYPOINT ["dotnet", "Jambo.Consumer.Infrastructure.dll"]
|
||||
ENTRYPOINT ["dotnet", "Jambo.Consumer.UI.dll"]
|
||||
34
source/Jambo.Consumer.UI/Jambo.Consumer.UI.csproj
Normal file
34
source/Jambo.Consumer.UI/Jambo.Consumer.UI.csproj
Normal file
@@ -0,0 +1,34 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;1705;NU1701</NoWarn>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac" Version="4.6.0" />
|
||||
<PackageReference Include="Autofac.Configuration" Version="4.0.1" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.0" />
|
||||
<PackageReference Include="MediatR" Version="3.0.1" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.EnvironmentVariables" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="2.0.0" />
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<PackageReference Include="Confluent.Kafka" Version="0.11.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Jambo.Consumer.Application\Jambo.Consumer.Application.csproj" />
|
||||
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
25
source/Jambo.Consumer.UI/Program.cs
Normal file
25
source/Jambo.Consumer.UI/Program.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
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)
|
||||
.AddJsonFile("autofac.json")
|
||||
.AddEnvironmentVariables();
|
||||
|
||||
IConfigurationRoot configuration = builder.Build();
|
||||
IServiceCollection serviceCollection = new ServiceCollection();
|
||||
|
||||
Startup startup = new Startup(configuration);
|
||||
startup.ConfigureServices(serviceCollection);
|
||||
startup.Run();
|
||||
}
|
||||
}
|
||||
}
|
||||
69
source/Jambo.Consumer.UI/Startup.cs
Normal file
69
source/Jambo.Consumer.UI/Startup.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
namespace Jambo.Consumer.Infrastructure
|
||||
{
|
||||
using Autofac;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using MediatR;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Loader;
|
||||
using Autofac.Configuration;
|
||||
using Jambo.Consumer.Application.DomainEventHandlers.Blogs;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
|
||||
public Startup(IConfiguration configuration)
|
||||
{
|
||||
Configuration = configuration;
|
||||
}
|
||||
|
||||
public IConfiguration Configuration { get; }
|
||||
|
||||
IServiceProvider serviceProvider;
|
||||
|
||||
public IServiceProvider ConfigureServices(IServiceCollection services)
|
||||
{
|
||||
LoadInfrastructureAssemblies();
|
||||
|
||||
services.AddMediatR(typeof(BlogCreatedEventHandler).GetTypeInfo().Assembly);
|
||||
|
||||
ContainerBuilder builder = new ContainerBuilder();
|
||||
builder.Populate(services);
|
||||
builder.RegisterModule(new ConfigurationModule(Configuration));
|
||||
|
||||
serviceProvider = new AutofacServiceProvider(builder.Build());
|
||||
|
||||
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()
|
||||
{
|
||||
IMediator mediator = serviceProvider.GetService<IMediator>();
|
||||
ISubscriber subscriber = serviceProvider.GetService<ISubscriber>();
|
||||
|
||||
subscriber.Listen(mediator);
|
||||
|
||||
while (true)
|
||||
{
|
||||
Console.WriteLine($"{DateTime.Now.ToString()} Waiting for events..");
|
||||
Thread.Sleep(1000 * 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
3
source/Jambo.Consumer.UI/appsettings.json
Normal file
3
source/Jambo.Consumer.UI/appsettings.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
|
||||
}
|
||||
19
source/Jambo.Consumer.UI/autofac.json
Normal file
19
source/Jambo.Consumer.UI/autofac.json
Normal file
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"defaultAssembly": "Jambo.Consumer.Infrastructure",
|
||||
"modules": [
|
||||
{
|
||||
"type": "Jambo.Consumer.Infrastructure.Modules.ApplicationModule",
|
||||
"properties": {
|
||||
"ConnectionString": "mongodb://10.0.75.1:27017",
|
||||
"DatabaseName": "jambov32"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Jambo.Consumer.Infrastructure.Modules.BusModule",
|
||||
"properties": {
|
||||
"BrokerList": "10.0.75.1:9092",
|
||||
"Topic": "jambov32"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Domain.UnitTests", "J
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Jambo.Consumer.Infrastructure", "Jambo.Consumer.Infrastructure\Jambo.Consumer.Infrastructure.csproj", "{645C9138-DA59-48C8-A15E-D720874DD148}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Jambo.Consumer.UI", "Jambo.Consumer.UI\Jambo.Consumer.UI.csproj", "{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
@@ -33,6 +35,10 @@ Global
|
||||
{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.Build.0 = Release|Any CPU
|
||||
{E86878A7-CB0F-46A7-B918-BED5C45BA4C5}.Debug|Any CPU.ActiveCfg = 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.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace Jambo.Domain.Model.Blogs.Events
|
||||
namespace Jambo.Domain.Model.Blogs.Events
|
||||
{
|
||||
using System;
|
||||
|
||||
public class BlogEnabledDomainEvent : DomainEvent
|
||||
{
|
||||
public BlogEnabledDomainEvent(Guid aggregateRootId, int version,
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
using Jambo.Domain.Model;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using MongoDB.Bson.Serialization;
|
||||
using MongoDB.Driver;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.DataAccess
|
||||
namespace Jambo.Producer.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
|
||||
{
|
||||
private readonly MongoClient mongoClient;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.DataAccess.Repositories.Blogs
|
||||
namespace Jambo.Producer.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
|
||||
{
|
||||
private readonly MongoContext _mongoContext;
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.DataAccess.Repositories.Posts
|
||||
namespace Jambo.Producer.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
|
||||
{
|
||||
private readonly MongoContext _mongoContext;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
<TargetFramework>netstandard2.0</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
@@ -9,7 +9,6 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Jambo.Producer.UI\Jambo.Producer.UI.csproj" />
|
||||
<PackageReference Include="Autofac" Version="4.6.0" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.0" />
|
||||
<PackageReference Include="MediatR" Version="3.0.1" />
|
||||
@@ -17,12 +16,16 @@
|
||||
<PackageReference Include="MongoDB.Driver" Version="2.4.4" />
|
||||
<PackageReference Include="Confluent.Kafka" Version="0.11.0" NoWarn="NU1701" />
|
||||
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="DataAccess\NewFolder\" />
|
||||
<ProjectReference Include="..\Jambo.Domain\Jambo.Domain.csproj" />
|
||||
<ProjectReference Include="..\Jambo.Producer.Application\Jambo.Producer.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="CopyFiles" AfterTargets="build">
|
||||
<Copy DestinationFolder="..\Jambo.Producer.UI\bin\Debug\netcoreapp2.0" SourceFiles="$(OutputPath)\Jambo.Producer.Infrastructure.dll" SkipUnchangedFiles="false" />
|
||||
<Copy DestinationFolder="..\Jambo.Producer.UI\bin\Debug\netcoreapp2.0" SourceFiles="$(OutputPath)\Jambo.Producer.Infrastructure.pdb" SkipUnchangedFiles="false" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -1,33 +1,23 @@
|
||||
using Autofac;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using Jambo.Producer.Infrastructure;
|
||||
using Jambo.Producer.Infrastructure.DataAccess;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Blogs;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Posts;
|
||||
using Jambo.Producer.Infrastructure.Queries;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Producer.Infrastructure.DataAccess;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Blogs;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Posts;
|
||||
|
||||
public class ApplicationModule : Module
|
||||
{
|
||||
public readonly string connectionString;
|
||||
public readonly string databaseName;
|
||||
|
||||
public ApplicationModule(string connectionString, string databaseName)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
public string ConnectionString { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<MongoContext>()
|
||||
.As<MongoContext>()
|
||||
.WithParameter("connectionString", connectionString)
|
||||
.WithParameter("databaseName", databaseName)
|
||||
.WithParameter("connectionString", ConnectionString)
|
||||
.WithParameter("databaseName", DatabaseName)
|
||||
.SingleInstance();
|
||||
|
||||
builder.RegisterType<BlogReadOnlyRepository>()
|
||||
|
||||
@@ -1,26 +1,20 @@
|
||||
using Autofac;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using Jambo.Producer.Infrastructure.ServiceBus;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using Jambo.Producer.Infrastructure.ServiceBus;
|
||||
|
||||
public class BusModule : Module
|
||||
{
|
||||
private readonly string brokerList;
|
||||
private readonly string topic;
|
||||
|
||||
public BusModule(string brokerList, string topic)
|
||||
{
|
||||
this.brokerList = brokerList;
|
||||
this.topic = topic;
|
||||
}
|
||||
public string BrokerList { get; set; }
|
||||
public string Topic { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<Bus>()
|
||||
.As<IPublisher>()
|
||||
.WithParameter("brokerList", brokerList)
|
||||
.WithParameter("topic", topic)
|
||||
.WithParameter("brokerList", BrokerList)
|
||||
.WithParameter("topic", Topic)
|
||||
.SingleInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
using Autofac;
|
||||
using Autofac.Features.Variance;
|
||||
using Jambo.Producer.Application.Commands.Blogs;
|
||||
using MediatR;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Autofac.Features.Variance;
|
||||
using Jambo.Producer.Application.Commands.Blogs;
|
||||
using MediatR;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
|
||||
public class MediatRModule : Autofac.Module
|
||||
{
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
|
||||
@@ -1,39 +1,26 @@
|
||||
using Autofac;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using Jambo.Producer.Infrastructure;
|
||||
using Jambo.Producer.Infrastructure.DataAccess;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Blogs;
|
||||
using Jambo.Producer.Infrastructure.DataAccess.Repositories.Posts;
|
||||
using Jambo.Producer.Infrastructure.Queries;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
namespace Jambo.Producer.Infrastructure.Modules
|
||||
{
|
||||
using Autofac;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using Jambo.Producer.Infrastructure.Queries;
|
||||
|
||||
public class QueriesModule : Module
|
||||
{
|
||||
public readonly string connectionString;
|
||||
public readonly string databaseName;
|
||||
|
||||
public QueriesModule(string connectionString, string databaseName)
|
||||
{
|
||||
this.connectionString = connectionString;
|
||||
this.databaseName = databaseName;
|
||||
}
|
||||
public string ConnectionString { get; set; }
|
||||
public string DatabaseName { get; set; }
|
||||
|
||||
protected override void Load(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterType<BlogQueries>()
|
||||
.As<IBlogQueries>()
|
||||
.WithParameter("connectionString", connectionString)
|
||||
.WithParameter("databaseName", databaseName)
|
||||
.WithParameter("connectionString", ConnectionString)
|
||||
.WithParameter("databaseName", DatabaseName)
|
||||
.SingleInstance();
|
||||
|
||||
builder.RegisterType<PostQueries>()
|
||||
.As<IPostQueries>()
|
||||
.WithParameter("connectionString", connectionString)
|
||||
.WithParameter("databaseName", databaseName)
|
||||
.WithParameter("connectionString", ConnectionString)
|
||||
.WithParameter("databaseName", DatabaseName)
|
||||
.SingleInstance();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureServices(services => services.AddAutofac())
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Queries
|
||||
namespace Jambo.Producer.Infrastructure.Queries
|
||||
{
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class BlogQueries : IBlogQueries
|
||||
{
|
||||
private readonly IMongoDatabase database;
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.Queries
|
||||
namespace Jambo.Producer.Infrastructure.Queries
|
||||
{
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MongoDB.Driver;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Dynamic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class PostQueries : IPostQueries
|
||||
{
|
||||
private readonly IMongoDatabase database;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using Confluent.Kafka;
|
||||
using Confluent.Kafka.Serialization;
|
||||
using Jambo.Domain.Model;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure.ServiceBus
|
||||
namespace Jambo.Producer.Infrastructure.ServiceBus
|
||||
{
|
||||
using Confluent.Kafka;
|
||||
using Confluent.Kafka.Serialization;
|
||||
using Jambo.Domain.Model;
|
||||
using Jambo.Domain.ServiceBus;
|
||||
using Newtonsoft.Json;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class Bus : IPublisher
|
||||
{
|
||||
public readonly string brokerList;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Producer.Application.Commands.Blogs;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.UI.Controllers
|
||||
namespace Jambo.Producer.UI.Controllers
|
||||
{
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Producer.Application.Commands.Blogs;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class BlogsController : Controller
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using Jambo.Producer.Application.Commands.Posts;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
|
||||
namespace Jambo.Producer.UI.Controllers
|
||||
namespace Jambo.Producer.UI.Controllers
|
||||
{
|
||||
using Jambo.Producer.Application.Commands.Posts;
|
||||
using MediatR;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Jambo.Domain.Model.Blogs;
|
||||
using Jambo.Domain.Model.Posts;
|
||||
using Jambo.Producer.Application.Queries;
|
||||
|
||||
[Authorize]
|
||||
[Route("api/[controller]")]
|
||||
public class PostsController : Controller
|
||||
|
||||
@@ -3,4 +3,4 @@ ARG source
|
||||
WORKDIR /app
|
||||
EXPOSE 80
|
||||
COPY ${source:-obj/Docker/publish} .
|
||||
ENTRYPOINT ["dotnet", "Jambo.Producer.Infrastructure.dll"]
|
||||
ENTRYPOINT ["dotnet", "Jambo.Producer.UI.dll"]
|
||||
@@ -1,14 +1,14 @@
|
||||
using Jambo.Producer.Application.Commands;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
{
|
||||
using Jambo.Producer.Application.Commands;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Linq;
|
||||
using System.Security.Claims;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class CorrelationFilter : ActionFilterAttribute
|
||||
{
|
||||
private Guid correlationId;
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
using Jambo.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
{
|
||||
using Jambo.Domain.Exceptions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public class DomainExceptionFilter : IExceptionFilter
|
||||
{
|
||||
public void OnException(ExceptionContext context)
|
||||
|
||||
@@ -1,12 +1,8 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
namespace Jambo.Producer.UI.Filters
|
||||
{
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
|
||||
public class ValidateModelAttribute : ActionFilterAttribute
|
||||
{
|
||||
public override void OnActionExecuting(ActionExecutingContext context)
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2.0</TargetFramework>
|
||||
@@ -6,13 +6,19 @@
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<NoWarn>1701;1702;1705;NU1701</NoWarn>
|
||||
<DocumentationFile>bin\Debug\netcoreapp2.0\Jambo.Producer.UI.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Autofac.Configuration" Version="4.0.1" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||
<PackageReference Include="Autofac" Version="4.6.0" />
|
||||
<PackageReference Include="Autofac.Extensions.DependencyInjection" Version="4.2.0" />
|
||||
<PackageReference Include="MediatR" Version="3.0.1" />
|
||||
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="2.0.0" />
|
||||
<PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="1.0.0" />
|
||||
<PackageReference Include="System.Runtime.Loader" Version="4.3.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
28
source/Jambo.Producer.UI/Program.cs
Normal file
28
source/Jambo.Producer.UI/Program.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
namespace Jambo.Producer.UI
|
||||
{
|
||||
using Microsoft.AspNetCore;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Autofac.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
|
||||
public class Program
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
BuildWebHost(args).Run();
|
||||
}
|
||||
|
||||
public static IWebHost BuildWebHost(string[] args)
|
||||
{
|
||||
return WebHost.CreateDefaultBuilder(args)
|
||||
.UseStartup<Startup>()
|
||||
.ConfigureAppConfiguration((builderContext, config) =>
|
||||
{
|
||||
IHostingEnvironment env = builderContext.HostingEnvironment;
|
||||
config.AddJsonFile("autofac.json");
|
||||
})
|
||||
.ConfigureServices(services => services.AddAutofac())
|
||||
.Build();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,21 @@
|
||||
using Autofac;
|
||||
using Jambo.Producer.Infrastructure.Modules;
|
||||
using Jambo.Producer.UI.Filters;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using System.Text;
|
||||
|
||||
namespace Jambo.Producer.Infrastructure
|
||||
namespace Jambo.Producer.UI
|
||||
{
|
||||
using Autofac;
|
||||
using Autofac.Configuration;
|
||||
using Jambo.Producer.UI.Filters;
|
||||
using Microsoft.AspNetCore.Authentication.JwtBearer;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Swashbuckle.AspNetCore.Swagger;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.Loader;
|
||||
using System.Text;
|
||||
|
||||
public class Startup
|
||||
{
|
||||
public Startup(IConfiguration configuration)
|
||||
@@ -71,19 +75,18 @@ namespace Jambo.Producer.Infrastructure
|
||||
|
||||
public void ConfigureContainer(ContainerBuilder builder)
|
||||
{
|
||||
builder.RegisterModule(new ApplicationModule(
|
||||
Configuration.GetSection("MongoDB").GetValue<string>("ConnectionString"),
|
||||
Configuration.GetSection("MongoDB").GetValue<string>("Database")));
|
||||
LoadInfrastructureAssemblies();
|
||||
builder.RegisterModule(new ConfigurationModule(Configuration));
|
||||
}
|
||||
|
||||
builder.RegisterModule(new BusModule(
|
||||
Configuration.GetSection("ServiceBus").GetValue<string>("ConnectionString"),
|
||||
Configuration.GetSection("ServiceBus").GetValue<string>("Topic")));
|
||||
private void LoadInfrastructureAssemblies()
|
||||
{
|
||||
string[] fileNames = Directory.EnumerateFiles(AppDomain.CurrentDomain.BaseDirectory, "*.dll", SearchOption.TopDirectoryOnly)
|
||||
.Where(filePath => Path.GetFileName(filePath).StartsWith("Jambo.Producer.Infrastructure", StringComparison.OrdinalIgnoreCase))
|
||||
.ToArray();
|
||||
|
||||
builder.RegisterModule(new MediatRModule());
|
||||
|
||||
builder.RegisterModule(new QueriesModule(
|
||||
Configuration.GetSection("MongoDB").GetValue<string>("ConnectionString"),
|
||||
Configuration.GetSection("MongoDB").GetValue<string>("Database")));
|
||||
foreach (string file in fileNames)
|
||||
AssemblyLoadContext.Default.LoadFromAssemblyPath(file);
|
||||
}
|
||||
|
||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||
10
source/Jambo.Producer.UI/appsettings.Development.json
Normal file
10
source/Jambo.Producer.UI/appsettings.Development.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,16 +13,6 @@
|
||||
}
|
||||
},
|
||||
|
||||
"MongoDB": {
|
||||
"ConnectionString": "mongodb://10.0.75.1:27017",
|
||||
"Database": "jambov32"
|
||||
},
|
||||
|
||||
"ServiceBus": {
|
||||
"ConnectionString": "10.0.75.1:9092",
|
||||
"Topic": "jambov32"
|
||||
},
|
||||
|
||||
"Security": {
|
||||
"SecretKey": "321B9B8C-C785-4DCF-88F7-39DCD935BDE2",
|
||||
"Issuer": "http://jambo"
|
||||
10
source/Jambo.Producer.UI/autofac.Development.json
Normal file
10
source/Jambo.Producer.UI/autofac.Development.json
Normal file
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"Logging": {
|
||||
"IncludeScopes": false,
|
||||
"LogLevel": {
|
||||
"Default": "Debug",
|
||||
"System": "Information",
|
||||
"Microsoft": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
31
source/Jambo.Producer.UI/autofac.json
Normal file
31
source/Jambo.Producer.UI/autofac.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"defaultAssembly": "Jambo.Producer.Infrastructure",
|
||||
"modules": [
|
||||
{
|
||||
"type": "Jambo.Producer.Infrastructure.Modules.ApplicationModule",
|
||||
"properties": {
|
||||
"ConnectionString": "mongodb://10.0.75.1:27017",
|
||||
"DatabaseName": "jambov32"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Jambo.Producer.Infrastructure.Modules.QueriesModule",
|
||||
"properties": {
|
||||
"ConnectionString": "mongodb://10.0.75.1:27017",
|
||||
"DatabaseName": "jambov32"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Jambo.Producer.Infrastructure.Modules.BusModule",
|
||||
"properties": {
|
||||
"BrokerList": "10.0.75.1:9092",
|
||||
"Topic": "jambov32"
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "Jambo.Producer.Infrastructure.Modules.MediatRModule",
|
||||
"properties": {
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in New Issue
Block a user