@@ -16,6 +16,8 @@ namespace DotNetCore.CAP | |||||
public void AddServices(IServiceCollection services) | public void AddServices(IServiceCollection services) | ||||
{ | { | ||||
services.AddSingleton<CapMessageQueueMakerService>(); | |||||
var kafkaOptions = new KafkaOptions(); | var kafkaOptions = new KafkaOptions(); | ||||
_configure?.Invoke(kafkaOptions); | _configure?.Invoke(kafkaOptions); | ||||
services.AddSingleton(kafkaOptions); | services.AddSingleton(kafkaOptions); | ||||
@@ -18,6 +18,7 @@ namespace DotNetCore.CAP | |||||
public void AddServices(IServiceCollection services) | public void AddServices(IServiceCollection services) | ||||
{ | { | ||||
services.AddSingleton<CapDatabaseStorageMarkerService>(); | |||||
services.AddSingleton<IStorage, MySqlStorage>(); | services.AddSingleton<IStorage, MySqlStorage>(); | ||||
services.AddScoped<IStorageConnection, MySqlStorageConnection>(); | services.AddScoped<IStorageConnection, MySqlStorageConnection>(); | ||||
services.AddScoped<ICapPublisher, CapPublisher>(); | services.AddScoped<ICapPublisher, CapPublisher>(); | ||||
@@ -18,6 +18,7 @@ namespace DotNetCore.CAP | |||||
public void AddServices(IServiceCollection services) | public void AddServices(IServiceCollection services) | ||||
{ | { | ||||
services.AddSingleton<CapDatabaseStorageMarkerService>(); | |||||
services.AddSingleton<IStorage, PostgreSqlStorage>(); | services.AddSingleton<IStorage, PostgreSqlStorage>(); | ||||
services.AddScoped<IStorageConnection, PostgreSqlStorageConnection>(); | services.AddScoped<IStorageConnection, PostgreSqlStorageConnection>(); | ||||
services.AddScoped<ICapPublisher, CapPublisher>(); | services.AddScoped<ICapPublisher, CapPublisher>(); | ||||
@@ -16,6 +16,8 @@ namespace DotNetCore.CAP | |||||
public void AddServices(IServiceCollection services) | public void AddServices(IServiceCollection services) | ||||
{ | { | ||||
services.AddSingleton<CapMessageQueueMakerService>(); | |||||
var options = new RabbitMQOptions(); | var options = new RabbitMQOptions(); | ||||
_configure?.Invoke(options); | _configure?.Invoke(options); | ||||
services.AddSingleton(options); | services.AddSingleton(options); | ||||
@@ -18,6 +18,7 @@ namespace DotNetCore.CAP | |||||
public void AddServices(IServiceCollection services) | public void AddServices(IServiceCollection services) | ||||
{ | { | ||||
services.AddSingleton<CapDatabaseStorageMarkerService>(); | |||||
services.AddSingleton<IStorage, SqlServerStorage>(); | services.AddSingleton<IStorage, SqlServerStorage>(); | ||||
services.AddSingleton<IStorageConnection, SqlServerStorageConnection>(); | services.AddSingleton<IStorageConnection, SqlServerStorageConnection>(); | ||||
services.AddTransient<ICapPublisher, CapPublisher>(); | services.AddTransient<ICapPublisher, CapPublisher>(); | ||||
@@ -1,7 +1,6 @@ | |||||
using System; | using System; | ||||
using DotNetCore.CAP; | using DotNetCore.CAP; | ||||
using DotNetCore.CAP.Dashboard.GatewayProxy; | using DotNetCore.CAP.Dashboard.GatewayProxy; | ||||
using Microsoft.AspNetCore.Http; | |||||
using Microsoft.Extensions.DependencyInjection; | using Microsoft.Extensions.DependencyInjection; | ||||
namespace Microsoft.AspNetCore.Builder | namespace Microsoft.AspNetCore.Builder | ||||
@@ -23,12 +22,7 @@ namespace Microsoft.AspNetCore.Builder | |||||
throw new ArgumentNullException(nameof(app)); | throw new ArgumentNullException(nameof(app)); | ||||
} | } | ||||
var marker = app.ApplicationServices.GetService<CapMarkerService>(); | |||||
if (marker == null) | |||||
{ | |||||
throw new InvalidOperationException("Add Cap must be called on the service collection."); | |||||
} | |||||
CheckRequirement(app); | |||||
var provider = app.ApplicationServices; | var provider = app.ApplicationServices; | ||||
var bootstrapper = provider.GetRequiredService<IBootstrapper>(); | var bootstrapper = provider.GetRequiredService<IBootstrapper>(); | ||||
@@ -36,21 +30,42 @@ namespace Microsoft.AspNetCore.Builder | |||||
return app; | return app; | ||||
} | } | ||||
///<summary> | |||||
/// Enables cap dashboard for the current application | |||||
/// </summary> | |||||
/// <param name="app">The <see cref="IApplicationBuilder"/> instance this method extends.</param> | |||||
/// <returns>The <see cref="IApplicationBuilder"/> instance this method extends.</returns> | |||||
public static IApplicationBuilder UseCapDashboard(this IApplicationBuilder app) | public static IApplicationBuilder UseCapDashboard(this IApplicationBuilder app) | ||||
{ | { | ||||
if (app == null) throw new ArgumentNullException(nameof(app)); | |||||
if (app == null) throw new ArgumentNullException(nameof(app)); | |||||
var marker = app.ApplicationServices.GetService<CapMarkerService>(); | |||||
CheckRequirement(app); | |||||
app.UseMiddleware<GatewayProxyMiddleware>(); | |||||
app.UseMiddleware<DashboardMiddleware>(); | |||||
return app; | |||||
} | |||||
private static void CheckRequirement(IApplicationBuilder app) | |||||
{ | |||||
var marker = app.ApplicationServices.GetService<CapMarkerService>(); | |||||
if (marker == null) | if (marker == null) | ||||
{ | { | ||||
throw new InvalidOperationException("Add Cap must be called on the service collection."); | |||||
throw new InvalidOperationException("AddCap must be called on the service collection. eg: services.AddCap(...)"); | |||||
} | } | ||||
app.UseMiddleware<GatewayProxyMiddleware>(); | |||||
app.UseMiddleware<DashboardMiddleware>(); | |||||
return app; | |||||
var messageQueuemarker = app.ApplicationServices.GetService<CapMessageQueueMakerService>(); | |||||
if (messageQueuemarker == null) | |||||
{ | |||||
throw new InvalidOperationException("You must be config used database provider at AddCap() options! eg: services.AddCap(options=>{ options.UseKafka(...) })"); | |||||
} | |||||
var databaseMarker = app.ApplicationServices.GetService<CapDatabaseStorageMarkerService>(); | |||||
if (databaseMarker == null) | |||||
{ | |||||
throw new InvalidOperationException("You must be config used database provider at AddCap() options! eg: services.AddCap(options=>{ options.UseSqlServer(...) })"); | |||||
} | |||||
} | } | ||||
} | } | ||||
} | } |
@@ -10,6 +10,22 @@ namespace DotNetCore.CAP | |||||
{ | { | ||||
} | } | ||||
/// <summary> | |||||
/// Used to verify cap database storage extension was added on a ServiceCollection | |||||
/// </summary> | |||||
public class CapDatabaseStorageMarkerService | |||||
{ | |||||
} | |||||
/// <summary> | |||||
/// Used to verify cap message queue extension was added on a ServiceCollection | |||||
/// </summary> | |||||
public class CapMessageQueueMakerService | |||||
{ | |||||
} | |||||
/// <summary> | /// <summary> | ||||
/// Allows fine grained configuration of CAP services. | /// Allows fine grained configuration of CAP services. | ||||
/// </summary> | /// </summary> | ||||