From f768e62d40278b4c22e13ce916a84c71ea63926a Mon Sep 17 00:00:00 2001 From: Savorboard Date: Thu, 19 Oct 2017 14:34:14 +0800 Subject: [PATCH] add custom content serializer extension to CapBuilder --- src/DotNetCore.CAP/CAP.Builder.cs | 32 +++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/src/DotNetCore.CAP/CAP.Builder.cs b/src/DotNetCore.CAP/CAP.Builder.cs index dd495ca..910256c 100644 --- a/src/DotNetCore.CAP/CAP.Builder.cs +++ b/src/DotNetCore.CAP/CAP.Builder.cs @@ -1,4 +1,5 @@ using System; +using DotNetCore.CAP.Abstractions; using Microsoft.Extensions.DependencyInjection; namespace DotNetCore.CAP @@ -27,7 +28,7 @@ namespace DotNetCore.CAP /// /// Allows fine grained configuration of CAP services. /// - public class CapBuilder + public sealed class CapBuilder { public CapBuilder(IServiceCollection services) { @@ -39,6 +40,26 @@ namespace DotNetCore.CAP /// public IServiceCollection Services { get; } + /// + /// Add an . + /// + /// The type of the service. + public CapBuilder AddProducerService() + where T : class, ICapPublisher + { + return AddScoped(typeof(ICapPublisher), typeof(T)); + } + + /// + /// Add a custom content serializer + /// + /// The type of the service. + public CapBuilder AddContentSerializer() + where T : class, IContentSerializer + { + return AddSingleton(typeof(IContentSerializer), typeof(T)); + } + /// /// Adds a scoped service of the type specified in serviceType with an implementation /// @@ -49,13 +70,12 @@ namespace DotNetCore.CAP } /// - /// Add an . + /// Adds a singleton service of the type specified in serviceType with an implementation /// - /// The type of the service. - public virtual CapBuilder AddProducerService() - where T : class, ICapPublisher + private CapBuilder AddSingleton(Type serviceType, Type concreteType) { - return AddScoped(typeof(ICapPublisher), typeof(T)); + Services.AddSingleton(serviceType, concreteType); + return this; } } } \ No newline at end of file