Commit 9de285b5 authored by yangxiaodong's avatar yangxiaodong

modify CapOptions Extension to support multiple extensions.

parent 5583f6af
using System; using System;
using System.Collections.Generic;
namespace DotNetCore.CAP namespace DotNetCore.CAP
{ {
...@@ -7,7 +8,7 @@ namespace DotNetCore.CAP ...@@ -7,7 +8,7 @@ namespace DotNetCore.CAP
/// </summary> /// </summary>
public class CapOptions public class CapOptions
{ {
internal ICapOptionsExtension Extension { get; private set; } internal IList<ICapOptionsExtension> Extensions { get; private set; }
/// <summary> /// <summary>
/// Default value for polling delay timeout, in seconds. /// Default value for polling delay timeout, in seconds.
...@@ -23,6 +24,7 @@ namespace DotNetCore.CAP ...@@ -23,6 +24,7 @@ namespace DotNetCore.CAP
{ {
CronExp = DefaultCronExp; CronExp = DefaultCronExp;
PollingDelay = DefaultPollingDelay; PollingDelay = DefaultPollingDelay;
Extensions = new List<ICapOptionsExtension>();
} }
/// <summary> /// <summary>
...@@ -41,7 +43,10 @@ namespace DotNetCore.CAP ...@@ -41,7 +43,10 @@ namespace DotNetCore.CAP
/// <param name="extension"></param> /// <param name="extension"></param>
public void RegisterExtension(ICapOptionsExtension extension) public void RegisterExtension(ICapOptionsExtension extension)
{ {
Extension = extension ?? throw new ArgumentNullException(nameof(extension)); if (extension == null)
throw new ArgumentNullException(nameof(extension));
Extensions.Add(extension);
} }
} }
} }
\ No newline at end of file
...@@ -53,10 +53,13 @@ namespace Microsoft.Extensions.DependencyInjection ...@@ -53,10 +53,13 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddSingleton<IQueueExecutorFactory, QueueExecutorFactory>(); services.AddSingleton<IQueueExecutorFactory, QueueExecutorFactory>();
services.AddSingleton<IQueueExecutor, SubscibeQueueExecutor>(); services.AddSingleton<IQueueExecutor, SubscibeQueueExecutor>();
//Options //Options and extension service
var options = new CapOptions(); var options = new CapOptions();
setupAction(options); setupAction(options);
options.Extension?.AddServices(services); foreach (var serviceExtension in options.Extensions)
{
serviceExtension.AddServices(services);
}
services.AddSingleton(options); services.AddSingleton(options);
return new CapBuilder(services); return new CapBuilder(services);
......
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