瀏覽代碼

add custom content serializer extension to CapBuilder

undefined
Savorboard 7 年之前
父節點
當前提交
f768e62d40
共有 1 個檔案被更改,包括 26 行新增6 行删除
  1. +26
    -6
      src/DotNetCore.CAP/CAP.Builder.cs

+ 26
- 6
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
/// <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…
取消
儲存