This repository has been archived by the owner on Dec 20, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 84
/
CompressionProviderCollection.cs
48 lines (43 loc) · 1.81 KB
/
CompressionProviderCollection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using System.Collections.ObjectModel;
namespace Microsoft.AspNetCore.ResponseCompression
{
/// <summary>
/// A Collection of ICompressionProvider's that also allows them to be instantiated from an <see cref="IServiceProvider" />.
/// </summary>
public class CompressionProviderCollection : Collection<ICompressionProvider>
{
/// <summary>
/// Adds a type representing an <see cref="ICompressionProvider"/>.
/// </summary>
/// <remarks>
/// Provider instances will be created using an <see cref="IServiceProvider" />.
/// </remarks>
public void Add<TCompressionProvider>() where TCompressionProvider : ICompressionProvider
{
Add(typeof(TCompressionProvider));
}
/// <summary>
/// Adds a type representing an <see cref="ICompressionProvider"/>.
/// </summary>
/// <param name="providerType">Type representing an <see cref="ICompressionProvider"/>.</param>
/// <remarks>
/// Provider instances will be created using an <see cref="IServiceProvider" />.
/// </remarks>
public void Add(Type providerType)
{
if (providerType == null)
{
throw new ArgumentNullException(nameof(providerType));
}
if (!typeof(ICompressionProvider).IsAssignableFrom(providerType))
{
throw new ArgumentException($"The provider must implement {nameof(ICompressionProvider)}.", nameof(providerType));
}
var factory = new CompressionProviderFactory(providerType);
Add(factory);
}
}
}