Browse Source

add custom content serializer extension to CapBuilder

undefined
Savorboard 7 years ago
parent
commit
f768e62d40
1 changed files with 26 additions and 6 deletions
  1. +26
    -6
      src/DotNetCore.CAP/CAP.Builder.cs

+ 26
- 6
src/DotNetCore.CAP/CAP.Builder.cs View File

@@ -1,4 +1,5 @@
using System;
using DotNetCore.CAP.Abstractions;
using Microsoft.Extensions.DependencyInjection;

namespace DotNetCore.CAP
@@ -27,7 +28,7 @@ namespace DotNetCore.CAP
/// <summary>
/// Allows fine grained configuration of CAP services.
/// </summary>
public class CapBuilder
public sealed class CapBuilder
{
public CapBuilder(IServiceCollection services)
{
@@ -39,6 +40,26 @@ namespace DotNetCore.CAP
/// </summary>
public IServiceCollection Services { get; }

/// <summary>
/// Add an <see cref="ICapPublisher" />.
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
public CapBuilder AddProducerService<T>()
where T : class, ICapPublisher
{
return AddScoped(typeof(ICapPublisher), typeof(T));
}

/// <summary>
/// Add a custom content serializer
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
public CapBuilder AddContentSerializer<T>()
where T : class, IContentSerializer
{
return AddSingleton(typeof(IContentSerializer), typeof(T));
}

/// <summary>
/// Adds a scoped service of the type specified in serviceType with an implementation
/// </summary>
@@ -49,13 +70,12 @@ namespace DotNetCore.CAP
}

/// <summary>
/// Add an <see cref="ICapPublisher" />.
/// Adds a singleton service of the type specified in serviceType with an implementation
/// </summary>
/// <typeparam name="T">The type of the service.</typeparam>
public virtual CapBuilder AddProducerService<T>()
where T : class, ICapPublisher
private CapBuilder AddSingleton(Type serviceType, Type concreteType)
{
return AddScoped(typeof(ICapPublisher), typeof(T));
Services.AddSingleton(serviceType, concreteType);
return this;
}
}
}

Loading…
Cancel
Save