Commit a75c0fd5 authored by yangxiaodong's avatar yangxiaodong

check the requirement when CAP start.

parent 74370557
......@@ -16,6 +16,8 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services)
{
services.AddSingleton<CapMessageQueueMakerService>();
var kafkaOptions = new KafkaOptions();
_configure?.Invoke(kafkaOptions);
services.AddSingleton(kafkaOptions);
......
......@@ -18,6 +18,7 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services)
{
services.AddSingleton<CapDatabaseStorageMarkerService>();
services.AddSingleton<IStorage, MySqlStorage>();
services.AddScoped<IStorageConnection, MySqlStorageConnection>();
services.AddScoped<ICapPublisher, CapPublisher>();
......
......@@ -18,6 +18,7 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services)
{
services.AddSingleton<CapDatabaseStorageMarkerService>();
services.AddSingleton<IStorage, PostgreSqlStorage>();
services.AddScoped<IStorageConnection, PostgreSqlStorageConnection>();
services.AddScoped<ICapPublisher, CapPublisher>();
......
......@@ -16,6 +16,8 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services)
{
services.AddSingleton<CapMessageQueueMakerService>();
var options = new RabbitMQOptions();
_configure?.Invoke(options);
services.AddSingleton(options);
......
......@@ -18,6 +18,7 @@ namespace DotNetCore.CAP
public void AddServices(IServiceCollection services)
{
services.AddSingleton<CapDatabaseStorageMarkerService>();
services.AddSingleton<IStorage, SqlServerStorage>();
services.AddSingleton<IStorageConnection, SqlServerStorageConnection>();
services.AddTransient<ICapPublisher, CapPublisher>();
......
using System;
using DotNetCore.CAP;
using DotNetCore.CAP.Dashboard.GatewayProxy;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
namespace Microsoft.AspNetCore.Builder
......@@ -23,12 +22,7 @@ namespace Microsoft.AspNetCore.Builder
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 bootstrapper = provider.GetRequiredService<IBootstrapper>();
......@@ -36,21 +30,42 @@ namespace Microsoft.AspNetCore.Builder
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)
{
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)
{
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(...) })");
}
}
}
}
\ No newline at end of file
......@@ -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>
/// Allows fine grained configuration of CAP services.
/// </summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment