Browse Source

modify CapOptions Extension to support multiple extensions.

master
yangxiaodong 7 years ago
parent
commit
9de285b5dd
2 changed files with 12 additions and 4 deletions
  1. +7
    -2
      src/DotNetCore.CAP/CAP.Options.cs
  2. +5
    -2
      src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs

+ 7
- 2
src/DotNetCore.CAP/CAP.Options.cs View File

@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;

namespace DotNetCore.CAP
{
@@ -7,7 +8,7 @@ namespace DotNetCore.CAP
/// </summary>
public class CapOptions
{
internal ICapOptionsExtension Extension { get; private set; }
internal IList<ICapOptionsExtension> Extensions { get; private set; }

/// <summary>
/// Default value for polling delay timeout, in seconds.
@@ -23,6 +24,7 @@ namespace DotNetCore.CAP
{
CronExp = DefaultCronExp;
PollingDelay = DefaultPollingDelay;
Extensions = new List<ICapOptionsExtension>();
}

/// <summary>
@@ -41,7 +43,10 @@ namespace DotNetCore.CAP
/// <param name="extension"></param>
public void RegisterExtension(ICapOptionsExtension extension)
{
Extension = extension ?? throw new ArgumentNullException(nameof(extension));
if (extension == null)
throw new ArgumentNullException(nameof(extension));

Extensions.Add(extension);
}
}
}

+ 5
- 2
src/DotNetCore.CAP/CAP.ServiceCollectionExtensions.cs View File

@@ -53,10 +53,13 @@ namespace Microsoft.Extensions.DependencyInjection
services.AddSingleton<IQueueExecutorFactory, QueueExecutorFactory>();
services.AddSingleton<IQueueExecutor, SubscibeQueueExecutor>();

//Options
//Options and extension service
var options = new CapOptions();
setupAction(options);
options.Extension?.AddServices(services);
foreach (var serviceExtension in options.Extensions)
{
serviceExtension.AddServices(services);
}
services.AddSingleton(options);

return new CapBuilder(services);


Loading…
Cancel
Save